F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
Engine.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Engine.cpp
3 // \brief CFDP Engine implementation
4 //
5 // This file is a port of CFDP engine operations from the following files
6 // from the NASA Core Flight System (cFS) CFDP (CF) Application, version 3.0.0,
7 // adapted for use within the F-Prime (F') framework:
8 // - cf_cfdp.c (CFDP PDU validation, processing, and engine operations)
9 //
10 // This file contains two sets of functions. The first is what is needed
11 // to deal with CFDP PDUs. Specifically validating them for correctness
12 // and ensuring the byte-order is correct for the target. The second
13 // is incoming and outgoing CFDP PDUs pass through here. All receive
14 // CFDP PDU logic is performed here and the data is passed to the
15 // R (rx) and S (tx) logic.
16 //
17 // ======================================================================
18 //
19 // NASA Docket No. GSC-18,447-1
20 //
21 // Copyright (c) 2019 United States Government as represented by the
22 // Administrator of the National Aeronautics and Space Administration.
23 // All Rights Reserved.
24 //
25 // Licensed under the Apache License, Version 2.0 (the "License"); you may
26 // not use this file except in compliance with the License. You may obtain
27 // a copy of the License at
28 //
29 // http://www.apache.org/licenses/LICENSE-2.0
30 //
31 // Unless required by applicable law or agreed to in writing, software
32 // distributed under the License is distributed on an "AS IS" BASIS,
33 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34 // See the License for the specific language governing permissions and
35 // limitations under the License.
36 //
37 // ======================================================================
38 
39 #include <string.h>
40 #include <new>
41 
42 #include <Fw/Types/StringUtils.hpp>
43 #include <Os/FilePathUtils.hpp>
44 #include <Os/FileSystem.hpp>
45 
52 
53 namespace Svc {
54 namespace Ccsds {
55 namespace Cfdp {
56 
57 // ----------------------------------------------------------------------
58 // Construction and destruction
59 // ----------------------------------------------------------------------
60 
61 Engine::Engine(CfdpManager* manager) : m_manager(manager), m_seqNum(0), m_allocator(nullptr), m_allocatorId(0) {
62  for (U8 i = 0; i < Cfdp::NumChannels; ++i) {
63  m_channels[i] = nullptr;
64  }
65 }
66 
68  FW_ASSERT(m_allocator != nullptr, 0); // init() must have been called
69 
70  for (U8 i = 0; i < Cfdp::NumChannels; ++i) {
71  if (m_channels[i] != nullptr) {
72  // Clean up Channel's internal arrays first
73  m_channels[i]->cleanup(*m_allocator, m_allocatorId);
74 
75  // Call destructor
76  m_channels[i]->~Channel();
77 
78  // Deallocate the Channel object itself
79  m_allocator->deallocate(m_allocatorId, m_channels[i]);
80  m_channels[i] = nullptr;
81  }
82  }
83 }
84 
85 // ----------------------------------------------------------------------
86 // Public interface methods
87 // ----------------------------------------------------------------------
88 
90  // Store allocator for cleanup in destructor
91  m_allocator = &allocator;
92  m_allocatorId = memId;
93 
94  // Allocate and construct all channels using the allocator
95  for (U8 i = 0; i < Cfdp::NumChannels; ++i) {
96  FwSizeType channelSize = sizeof(Channel);
97  void* channelMem = allocator.allocate(memId, channelSize);
98  FW_ASSERT(channelMem != nullptr);
99 
100  // Use placement new to construct Channel in allocated memory
101  m_channels[i] = new (channelMem) Channel(this, i, this->m_manager, allocator, memId);
102  }
103 }
104 
106  txn->m_ack_timer.setTimer(txn->m_cfdpManager->getAckTimerParam(txn->m_chan_num));
107  txn->m_flags.com.ack_timer_armed = true;
108 }
109 
111  U32 timerDuration = 0;
112 
113  // select timeout based on the state
115  // in an active transaction, we expect traffic so use the normal inactivity timer
116  timerDuration = txn->m_cfdpManager->getInactivityTimerParam(txn->m_chan_num);
117  } else {
118  // in an inactive transaction, we do NOT expect traffic, and this timer is now used
119  // just in case any late straggler PDUs dp get delivered. In this case the
120  // time should be longer than the retransmit time (ack timer) but less than the full
121  // inactivity timer (because again, we are not expecting traffic, so waiting the full
122  // timeout would hold resources longer than needed). Using double the ack timer should
123  // ensure that if the remote retransmitted anything, we will see it, and avoids adding
124  // another config option just for this.
125  timerDuration = txn->m_cfdpManager->getAckTimerParam(txn->m_chan_num) * 2;
126  }
127 
128  txn->m_inactivity_timer.setTimer(timerDuration);
129 }
130 
131 void Engine::dispatchRecv(Transaction* txn, const Fw::Buffer& buffer) {
132  // Loop to handle state transitions without recursion
133  // The loop allows recvInit to transition to R2 state and re-dispatch
134  bool needsDispatch = true;
135  while (needsDispatch) {
136  needsDispatch = false; // Assume single dispatch unless state handler requests re-dispatch
137 
138  // Dispatch based on transaction state
139  switch (txn->m_state) {
141  needsDispatch = this->recvInit(txn, buffer);
142  break;
144  txn->r1Recv(buffer);
145  break;
147  txn->s1Recv(buffer);
148  break;
150  txn->r2Recv(buffer);
151  break;
153  txn->s2Recv(buffer);
154  break;
156  this->recvDrop(txn, buffer);
157  break;
159  this->recvHold(txn, buffer);
160  break;
161  default:
162  // Invalid or undefined state
163  break;
164  }
165  }
166 
167  // Whenever a packet was received from the other side, re-arm its inactivity timer, unless the
168  // transaction was abandoned during dispatch and already sits on the FREE queue
169  if (txn->m_flags.com.q_index != QueueId::FREE) {
170  this->armInactTimer(txn);
171  }
172 }
173 
175  static const TxnSendDispatchTable state_fns = {{
176  nullptr, // TxnState::TXN_STATE_UNDEF
177  nullptr, // TxnState::TXN_STATE_INIT
178  nullptr, // TxnState::TXN_STATE_R1
179  &Transaction::s1Tx, // TxnState::TXN_STATE_S1
180  nullptr, // TxnState::TXN_STATE_R2
181  &Transaction::s2Tx, // TxnState::TXN_STATE_S2
182  nullptr, // TxnState::TXN_STATE_DROP
183  nullptr // TxnState::TXN_STATE_HOLD
184  }};
185 
186  txn->txStateDispatch(&state_fns);
187 }
188 
190  FW_ASSERT((txn->m_state == TxnState::TXN_STATE_S1) || (txn->m_state == TxnState::TXN_STATE_S2),
191  static_cast<U8>(txn->m_state));
192  FW_ASSERT(txn->m_chan != nullptr);
193 
194  // Create and initialize Metadata PDU
195  MetadataPdu md;
196 
197  // Set closure requested flag based on transaction class
198  // Class 1: closure not requested (0), Class 2: closure requested (1)
199  U8 closureRequested = (txn->m_state == TxnState::TXN_STATE_S2) ? 1 : 0;
200 
201  // Direction is toward receiver for metadata PDU sent by sender
203 
204  md.initialize(direction,
205  txn->getClass(), // transmission mode (Class 1 or 2)
206  m_manager->getLocalEidParam(), // source EID
207  txn->m_history->seq_num, // transaction sequence number
208  txn->m_history->peer_eid, // destination EID
209  txn->m_fsize, // file size
210  txn->m_history->fnames.src_filename, // source filename
211  txn->m_history->fnames.dst_filename, // destination filename
212  ChecksumType::CHECKSUM_TYPE_MODULAR, // checksum type
213  closureRequested // closure requested flag
214  );
215 
216  return serializeAndSendPdu(txn, md);
217 }
218 
220  Status::T status = serializeAndSendPdu(txn, fdPdu);
221  if (status == Cfdp::Status::SUCCESS) {
222  m_manager->addSentFileDataBytes(txn->getChannelId(), fdPdu.getDataSize());
223  }
224  return status;
225 }
226 
228  // Create and initialize EOF PDU
229  EofPdu eof;
230 
231  // Direction is toward receiver for EOF sent by sender
233  ConditionCode conditionCode = static_cast<ConditionCode>(TxnStatusToConditionCode(txn->m_history->txn_stat));
234 
235  // Increment sent EOF counters based on condition code
237  this->m_manager->incrementSentEofCanceled(txn->getChannelId());
238  } else if (conditionCode != ConditionCode::CONDITION_CODE_NO_ERROR) {
239  this->m_manager->incrementFaultTxEofError(txn->getChannelId());
240  }
241 
242  eof.initialize(direction,
243  txn->getClass(), // transmission mode
244  m_manager->getLocalEidParam(), // source EID
245  txn->m_history->seq_num, // transaction sequence number
246  txn->m_history->peer_eid, // destination EID
247  conditionCode, // condition code
248  txn->m_crc.getValue(), // checksum
249  txn->m_fsize // file size
250  );
251 
252  // Add entity ID TLV on error conditions (optional per CCSDS spec)
253  if (conditionCode != ConditionCode::CONDITION_CODE_NO_ERROR) {
254  Cfdp::Tlv tlv;
255  tlv.initialize(m_manager->getLocalEidParam()); // Local entity ID
256  eof.appendTlv(tlv);
257  }
258 
259  return serializeAndSendPdu(txn, eof);
260 }
261 
263  AckTxnStatus ts,
264  FileDirective dir_code,
265  ConditionCode cc,
266  EntityId peer_eid,
267  TransactionSeq tsn) {
268  FW_ASSERT(
270  static_cast<U8>(dir_code));
271 
272  // Determine source and destination EIDs based on transaction direction
273  EntityId src_eid;
274  EntityId dst_eid;
275  if (txn->getHistory()->dir == Direction::DIRECTION_TX) {
276  src_eid = m_manager->getLocalEidParam();
277  dst_eid = peer_eid;
278  } else {
279  src_eid = peer_eid;
280  dst_eid = m_manager->getLocalEidParam();
281  }
282 
283  // Create and initialize ACK PDU
284  AckPdu ack;
285 
286  // Direction: toward sender for EOF ACK, toward receiver for FIN ACK
290 
291  ack.initialize(direction,
292  txn->getClass(), // transmission mode
293  src_eid, // source EID
294  tsn, // transaction sequence number
295  dst_eid, // destination EID
296  dir_code, // directive being acknowledged
297  1, // directive subtype code (always 1)
298  cc, // condition code
299  ts // transaction status
300  );
301 
302  return serializeAndSendPdu(txn, ack);
303 }
304 
306  // Create and initialize FIN PDU
307  FinPdu fin;
308 
309  // Direction is toward sender for FIN sent by receiver
311 
312  fin.initialize(direction,
313  txn->getClass(), // transmission mode
314  txn->m_history->peer_eid, // source EID (receiver)
315  txn->m_history->seq_num, // transaction sequence number
316  m_manager->getLocalEidParam(), // destination EID (sender)
317  cc, // condition code
318  static_cast<FinDeliveryCode>(dc), // delivery code
319  static_cast<FinFileStatus>(fs) // file status
320  );
321 
322  // Add entity ID TLV on error conditions (optional per CCSDS spec)
324  Cfdp::Tlv tlv;
325  tlv.initialize(m_manager->getLocalEidParam()); // Local entity ID
326  fin.appendTlv(tlv);
327  }
328 
329  return serializeAndSendPdu(txn, fin);
330 }
331 
333  // Verify this is a Class 2 transaction (NAK only used in Class 2)
334  Class::T tx_class = txn->getClass();
335  FW_ASSERT(tx_class == Cfdp::Class::CLASS_2, tx_class);
336 
337  return serializeAndSendPdu(txn, nakPdu);
338 }
339 
340 Status::T Engine::serializeAndSendPdu(Transaction* txn, PduBase& pdu) {
341  // Delegate to the channel-based helper; a transaction always carries its channel.
342  return this->serializeAndSendPduOnChannel(*txn->m_chan, pdu);
343 }
344 
345 Status::T Engine::serializeAndSendPduOnChannel(Channel& chan, PduBase& pdu) {
346  Fw::Buffer buffer;
348 
349  // Allocate buffer with space for packet descriptor
350  const FwSizeType bufferSize = pdu.getBufferSize() + CfdpManager::PACKET_DESCRIPTOR_SIZE;
351  status = m_manager->getPduBuffer(buffer, chan, bufferSize);
352 
353  if (status == Cfdp::Status::SUCCESS) {
354  // Serialize to buffer at offset to leave room for descriptor
357  Fw::SerializeStatus serStatus = pdu.serializeTo(sb);
358 
359  if (serStatus != Fw::FW_SERIALIZE_OK) {
360  // Log generic PDU serialization error with PDU type
361  m_manager->log_WARNING_LO_FailPduSerialization(chan.getChannelId(), pdu.getType(),
362  static_cast<I32>(serStatus));
363  m_manager->returnPduBuffer(chan, buffer);
364  status = Cfdp::Status::ERROR;
365  } else {
366  // Update buffer size to actual serialized size plus descriptor
367  buffer.setSize(sb.getSize() + CfdpManager::PACKET_DESCRIPTOR_SIZE);
368  m_manager->sendPduBuffer(chan, buffer);
369  m_manager->incrementSentPdu(chan.getChannelId());
370  }
371  }
372 
373  return status;
374 }
375 
376 Status::T Engine::sendFinAckStateless(Channel& chan,
377  TransactionSeq tsn,
378  EntityId finSrcEid,
379  EntityId finDstEid,
380  ConditionCode cc) {
381  // A FIN has arrived for a downlink transaction we sourced, but no live transaction
382  // remains (it already completed and was recycled). Per CFDP the sender must still
383  // acknowledge a retransmitted FIN; we do so statelessly from the FIN header.
384  //
385  // The FIN was sent toward us (the sender), so its header carries
386  // sourceEid = the transaction source = this local entity,
387  // destEid = the peer (receiver).
388  // The ACK(FIN) we emit travels toward the receiver, mirroring Engine::sendAck's
389  // DIRECTION_TX case: src = local entity, dst = peer.
390  AckPdu ack;
392  Cfdp::Class::CLASS_2, // FIN/ACK only exist in class 2
393  finSrcEid, // source EID (this local entity)
394  tsn, // transaction sequence number
395  finDstEid, // destination EID (the peer/receiver)
396  FileDirective::FILE_DIRECTIVE_FIN, // directive being acknowledged
397  1, // directive subtype code (always 1)
398  cc, // echo the FIN's condition code
399  AckTxnStatus::ACK_TXN_STATUS_UNRECOGNIZED // we no longer recognize this transaction
400  );
401 
402  return this->serializeAndSendPduOnChannel(chan, ack);
403 }
404 
406  Fw::String rxDir = this->m_manager->getRxDirParam(chan_num);
407  if (rxDir.length() == 0) {
408  // Sandbox not configured for this channel: accept path as-is (documented fail-open behavior)
409  return true;
410  }
411 
412  // Canonicalize the receive directory (relative rx_dir resolves against CWD) into the
413  // trailing-'/' form that checkContainment requires; shared with Os::SandboxedFile
415  if (Os::FilePathUtils::resolveDirectoryFromCwd(rxDir.toChar(), root, sizeof(root)) != Os::FilePathUtils::VALID) {
417  return false;
418  }
419 
420  // Resolve the received path: relative paths land inside the receive directory, `..` segments
421  // are collapsed textually (symlinks are not followed; see Os::SandboxedFile threat model)
422  char resolved[Os::FilePathUtils::MAX_PATH_LENGTH];
423  if (Os::FilePathUtils::resolvePath(path.toChar(), root, resolved, sizeof(resolved)) != Os::FilePathUtils::VALID) {
425  return false;
426  }
429  return false;
430  }
431  // The canonical path is stored in the transaction and reported in events sized to
432  // MaxFilePathSize; reject rather than silently truncate a longer result
433  if (Fw::StringUtils::string_length(resolved, sizeof(resolved)) > Cfdp::MaxFilePathSize) {
435  return false;
436  }
437 
438  path = resolved;
439  return true;
440 }
441 
443  /* the destination path comes from the remote entity: canonicalize it and confirm it lies within
444  * the configured receive directory BEFORE anything from this PDU is committed to the transaction.
445  * On rejection nothing from the PDU (file size, source name, destination) is stored; the only
446  * change to the transaction is its status, set below. */
447  Fw::String dst = md.getDestFilename();
448  RxDestPathRejectReason reason;
449  if (!this->validateRxDestPath(txn->m_chan_num, dst, reason)) {
450  this->m_manager->log_WARNING_HI_RxDestPathRejected(txn->m_chan_num, txn->m_history->src_eid,
451  txn->m_history->seq_num, dst,
452  this->m_manager->getRxDirParam(txn->m_chan_num), reason);
453  this->m_manager->incrementFaultFileOpen(txn->m_chan_num);
454  // Refused destination = filestore rejection, so finishTransaction reports a failed reception.
455  // Whether the sender learns of it depends on the caller; see the recvMd doc in Engine.hpp.
458  }
459 
460  /* store the expected file size in transaction */
461  txn->m_fsize = md.getFileSize();
462 
463  /* structural validation (length, non-empty) already done during deserialization */
464  txn->m_history->fnames.src_filename = md.getSourceFilename();
465  txn->m_history->fnames.dst_filename = dst;
466 
467  this->m_manager->log_ACTIVITY_LO_MetadataReceived(txn->m_history->fnames.src_filename,
468  txn->m_history->fnames.dst_filename, txn->m_history->seq_num);
469  return Status::SUCCESS;
470 }
471 
474 
475  // Extract header
476  const Cfdp::PduHeader& header = fd.asHeader();
477 
478  // Check for segment metadata flag (not currently supported)
479  if (header.hasSegmentMetadata()) {
480  /* If recv PDU has the "segment_meta_flag" set, this is not currently handled in CF. */
481  this->m_manager->log_WARNING_LO_FileDataSegmentMetadata();
483  this->m_manager->incrementRecvErrors(txn->getChannelId());
484  ret = Cfdp::Status::ERROR;
485  }
486 
487  return ret;
488 }
489 
491  // EOF PDU has been validated during fromBuffer()
492 
493  // Process TLVs if present
494  const Cfdp::TlvList& tlvList = eofPdu.getTlvList();
495  for (U8 i = 0; i < tlvList.getNumTlv(); i++) {
496  const Cfdp::Tlv& tlv = tlvList.getTlv(i);
498  // Entity ID TLV present - validation not currently performed
499  // Future enhancement: Add validation or logging if required
500  }
501  // Other TLV types can be processed here in the future
502  }
503 
504  return Cfdp::Status::SUCCESS;
505 }
506 
508  // FIN PDU has been validated during fromBuffer()
509 
510  // Process TLVs if present
511  const Cfdp::TlvList& tlvList = finPdu.getTlvList();
512  for (U8 i = 0; i < tlvList.getNumTlv(); i++) {
513  const Cfdp::Tlv& tlv = tlvList.getTlv(i);
515  // Entity ID TLV present - validation not currently performed
516  // Future enhancement: Add validation or logging if required
517  }
518  // Other TLV types can be processed here in the future
519  }
520 
521  return Cfdp::Status::SUCCESS;
522 }
523 
525  // NAK PDU has been validated during fromBuffer()
526  return Cfdp::Status::SUCCESS;
527 }
528 
529 void Engine::recvDrop(Transaction* txn, const Fw::Buffer& buffer) {
530  this->m_manager->incrementRecvDropped(txn->getChannelId());
531  (void)buffer; // Unused - we're just dropping the PDU
532 }
533 
534 void Engine::recvHold(Transaction* txn, const Fw::Buffer& buffer) {
535  // anything received in this state is considered spurious
536  this->m_manager->incrementRecvSpurious(txn->getChannelId());
537 
538  //
539  // Normally we do not expect PDUs for a transaction in holdover, because
540  // from the local point of view it is completed and done. But the reason
541  // for the holdover is because the remote side might not have gotten all
542  // the acks and could still be [re-]sending us PDUs for anything it does
543  // not know we got already.
544  //
545  // If an R2 sent FIN, it's possible that the peer missed the
546  // FIN-ACK and is sending another FIN. In that case we need to send
547  // another ACK.
548  //
549 
550  // currently the only thing we will re-ack is the FIN.
551 
552  // Use peekPduType to determine the PDU type
553  Cfdp::PduTypeEnum::T pduType = Cfdp::peekPduType(buffer);
554 
555  // Check if this is a FIN PDU for a Class 2 transaction
556  if (pduType == Cfdp::PduTypeEnum::FINISHED && txn->getClass() == Cfdp::Class::CLASS_2) {
557  // Deserialize FIN PDU
558  FinPdu fin;
559  Fw::SerialBuffer sb2(const_cast<U8*>(buffer.getData()), buffer.getSize());
560  sb2.setBuffLen(buffer.getSize());
561 
562  Fw::SerializeStatus deserStatus = fin.deserializeFrom(sb2);
563  if (deserStatus == Fw::FW_SERIALIZE_OK) {
564  // Re-send the FIN-ACK
566  fin.getConditionCode(), txn->m_history->peer_eid, txn->m_history->seq_num);
567  }
568  // Note: Deserialization errors are silently ignored in hold state
569  // as we're just trying to be helpful by re-acknowledging FIN if we can
570  }
571 }
572 
573 bool Engine::recvInit(Transaction* txn, const Fw::Buffer& buffer) {
574  // Use peekPduType to determine the PDU type before deserializing
575  Cfdp::PduTypeEnum::T pduType = Cfdp::peekPduType(buffer);
576 
577  // First parse header to get transaction information
578  // const_cast: Fw::SerialBuffer requires non-const U8* even for deserialization (read-only)
579  Fw::SerialBuffer sb(const_cast<U8*>(buffer.getData()), buffer.getSize());
580  sb.setBuffLen(buffer.getSize());
581 
582  Cfdp::PduHeader header;
583  Fw::SerializeStatus status = header.fromSerialBuffer(sb);
584 
585  if (status == Fw::FW_SERIALIZE_OK) {
586  TransactionSeq transactionSeq = header.getTransactionSeq();
587  EntityId sourceEid = header.getSourceEid();
588  Class::T txmMode = header.getTxmMode();
589 
590  // only RX transactions dare tread here
591  txn->m_history->seq_num = transactionSeq;
592 
593  // peer_eid is always the remote partner. src_eid is always the transaction source.
594  // in this case, they are the same
595  txn->m_history->peer_eid = sourceEid;
596  txn->m_history->src_eid = sourceEid;
597 
598  // all RX transactions will need a chunk list to track file segments
599  if (txn->m_chunks == nullptr) {
600  txn->m_chunks = txn->m_chan->findUnusedChunks(Direction::DIRECTION_RX);
601  }
602  if (txn->m_chunks == nullptr) {
603  this->m_manager->log_WARNING_LO_ChunklistUnavailable(transactionSeq);
604  } else {
605  if (pduType == Cfdp::PduTypeEnum::FILE_DATA) {
606  // file data PDU
607  // being idle and receiving a file data PDU means that no active transaction knew
608  // about the transaction in progress, so most likely PDUs were missed.
609 
610  if (txmMode == Cfdp::Class::CLASS_1) {
611  // R1, can't do anything without metadata first
612  txn->m_state = TxnState::TXN_STATE_DROP; // drop all incoming
613  // use inactivity timer to ultimately free the state
614  } else {
615  // R2 can handle missing metadata, so go ahead and create a temp file
616  txn->m_state = TxnState::TXN_STATE_R2;
617  txn->m_txn_class = Cfdp::Class::CLASS_2;
618  txn->rInit();
619  return true; // Request re-dispatch to enter r2 state handler
620  }
621  } else if (pduType == Cfdp::PduTypeEnum::METADATA) {
622  // file directive PDU with metadata - this is the expected case for starting a new RX transaction
623  MetadataPdu md;
624  Fw::SerialBuffer sb2(const_cast<U8*>(buffer.getData()), buffer.getSize());
625  sb2.setBuffLen(buffer.getSize());
626 
627  Fw::SerializeStatus deserStatus = md.deserializeFrom(sb2);
628  if (deserStatus == Fw::FW_SERIALIZE_OK) {
629  if (this->recvMd(txn, md) == Status::SUCCESS) {
630  // NOTE: whether or not class 1 or 2, get a free chunks. It's cheap, and simplifies cleanup
631  // path
632  txn->m_state =
634  txn->m_txn_class = txmMode;
635  txn->m_flags.rx.md_recv = true;
636  txn->rInit(); // initialize R
637  }
638  // else: destination path rejected and the transaction marked FILESTORE_REJECTION.
639  // State stays INIT so the transaction is finished below as a failed reception
640  // (parked in HOLD until the inactivity timer recycles it) without any file
641  // ever being opened.
642  } else {
643  m_manager->log_WARNING_LO_FailMetadataPduDeserialization(txn->getChannelId(),
644  static_cast<I32>(deserStatus));
645  }
646  } else {
647  // Unexpected PDU type in init state
648  this->m_manager->log_WARNING_LO_UnhandledPduInIdleState();
649  this->m_manager->incrementRecvErrors(txn->getChannelId());
650  }
651  }
652 
653  } else {
654  m_manager->log_WARNING_LO_FailPduHeaderDeserialization(txn->getChannelId(), status);
655  }
656 
657  if (txn->m_state == TxnState::TXN_STATE_INIT) {
658  if (TxnStatusIsError(txn->m_history->txn_stat)) {
659  // A transfer was identified and refused (e.g. destination path rejected). Report
660  // it as a failed reception and park the slot in HOLD so the inactivity timer
661  // recycles it, as for any other failed transaction.
662  this->finishTransaction(txn, false);
663  } else {
664  // The PDU could not start a transaction, so nothing was transferred. Release the
665  // slot now rather than routing through finishTransaction(), which would report a
666  // completed transfer and park the slot in HOLD until the inactivity timer expires.
667  // Holding slots for PDUs that never start a transaction lets a stream of stray
668  // PDUs exhaust the pool shared with commanded transmit transactions.
669  this->abandonInitTransaction(txn);
670  }
671  }
672  return false; // No re-dispatch needed
673 }
674 
676  FW_ASSERT(txn != nullptr);
677  FW_ASSERT(txn->m_state == TxnState::TXN_STATE_INIT, static_cast<FwAssertArgType>(txn->m_state));
678  FW_ASSERT(txn->m_chan != nullptr);
679 
680  txn->m_chan->clearCurrentIfMatch(txn);
681  // Returns chunk list and history, then places the transaction back on the FREE queue
682  txn->m_chan->recycleTransaction(txn);
683 }
684 
685 void Engine::receivePdu(U8 chan_id, const Fw::Buffer& buffer) {
686  Transaction* txn = nullptr;
687  Channel* chan = nullptr;
688 
689  FW_ASSERT(chan_id < Cfdp::NumChannels, chan_id, Cfdp::NumChannels);
690 
691  chan = m_channels[chan_id];
692  FW_ASSERT(chan != nullptr);
693 
694  // Parse the header to get transaction routing info
695  // Avoid full PDU deserialization here to defer it until the appropriate handler
696  // const_cast: Fw::SerialBuffer requires non-const U8* even for deserialization (read-only)
697  Fw::SerialBuffer sb(const_cast<U8*>(buffer.getData()), buffer.getSize());
698  sb.setBuffLen(buffer.getSize());
699 
700  Cfdp::PduHeader header;
701  Fw::SerializeStatus status = header.fromSerialBuffer(sb);
702 
703  if (status == Fw::FW_SERIALIZE_OK) {
704  // Increment received PDU counter for PDUs with valid headers
705  this->m_manager->incrementRecvPdu(chan_id);
706 
707  TransactionSeq transactionSeq = header.getTransactionSeq();
708  EntityId sourceEid = header.getSourceEid();
709  EntityId destEid = header.getDestEid();
710 
711  // Look up transaction by sequence number
712  txn = chan->findTransactionBySequenceNumber(transactionSeq, sourceEid);
713 
714  if (txn == nullptr) {
715  // A retransmitted FIN can arrive for a downlink transaction we sourced after
716  // that transaction has already completed and been recycled (e.g. the peer
717  // kept retransmitting FIN across a lossy/quiet link). Per CFDP the sender
718  // must still acknowledge it, so re-ACK statelessly from the FIN header.
719  // Such a FIN carries sourceEid == our local entity (we were the source) and
720  // destEid == the peer, so it would otherwise be dropped as InvalidDestinationEid.
722  sourceEid == this->m_manager->getLocalEidParam()) {
723  FinPdu fin;
724  Fw::SerialBuffer finSb(const_cast<U8*>(buffer.getData()), buffer.getSize());
725  finSb.setBuffLen(buffer.getSize());
726  if (fin.deserializeFrom(finSb) == Fw::FW_SERIALIZE_OK) {
727  this->sendFinAckStateless(*chan, transactionSeq, sourceEid, destEid, fin.getConditionCode());
728  this->m_manager->log_DIAGNOSTIC_TxLateFinAcked(sourceEid, transactionSeq);
729  } else {
731  chan_id, static_cast<I32>(Fw::FW_DESERIALIZE_FORMAT_ERROR));
732  }
733  }
734  // if no match found, then it must be the case that we would be the destination entity id, so verify it
735  else if (destEid == this->m_manager->getLocalEidParam()) {
736  // we didn't find a match, so assign it to a transaction
737  // assume this is initiating an RX transaction, as TX transactions are only commanded
738  txn = this->startRxTransaction(chan->getChannelId());
739  if (txn == nullptr) {
740  this->m_manager->log_WARNING_LO_RxTransactionLimitReached(sourceEid, transactionSeq);
741  }
742  } else {
743  this->m_manager->log_WARNING_LO_InvalidDestinationEid(destEid);
744  }
745  }
746 
747  if (txn != nullptr) {
748  // found one! Send it to the transaction state processor
749  this->dispatchRecv(txn, buffer);
750  } else {
751  // Transaction limit reached - EVR already emitted by findOrStartRxTransaction
752  }
753  } else {
754  // Invalid PDU header, drop packet
755  m_manager->log_WARNING_LO_FailPduHeaderDeserialization(chan_id, static_cast<I32>(status));
756  }
757 }
758 
759 void Engine::setChannelFlowState(U8 channelId, Flow::T flowState) {
760  FW_ASSERT(channelId < Cfdp::NumChannels, channelId, Cfdp::NumChannels);
761  m_channels[channelId]->setFlowState(flowState);
762 }
763 
765  TransactionSeq transactionSeq,
766  EntityId entityId,
767  SuspendResume::T action) {
768  Status::T status = Status::ERROR;
769 
770  FW_ASSERT(channelId < Cfdp::NumChannels, channelId, Cfdp::NumChannels);
771 
772  Channel* chan = m_channels[channelId];
773  Transaction* txn = chan->findTransactionBySequenceNumber(transactionSeq, entityId);
774 
775  if (txn != nullptr) {
776  txn->m_flags.com.suspended = (action == SuspendResume::SUSPEND);
777  status = Status::SUCCESS;
778  }
779 
780  return status;
781 }
782 
783 Status::T Engine::cancelTransactionBySeq(U8 channelId, TransactionSeq transactionSeq, EntityId entityId) {
784  Status::T status = Status::ERROR;
785 
786  FW_ASSERT(channelId < Cfdp::NumChannels, channelId, Cfdp::NumChannels);
787 
788  Channel* chan = m_channels[channelId];
789  Transaction* txn = chan->findTransactionBySequenceNumber(transactionSeq, entityId);
790 
791  if (txn != nullptr) {
792  this->cancelTransaction(txn);
793  status = Status::SUCCESS;
794  }
795 
796  return status;
797 }
798 
799 Status::T Engine::abandonTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId) {
800  Status::T status = Status::ERROR;
801 
802  FW_ASSERT(channelId < Cfdp::NumChannels, channelId, Cfdp::NumChannels);
803 
804  Channel* chan = m_channels[channelId];
805  Transaction* txn = chan->findTransactionBySequenceNumber(transactionSeq, entityId);
806 
807  // A finished transaction stays findable in HOLD until its inactivity timer recycles it.
808  // There is nothing left to abandon, so report it the same as a transaction that is not found.
809  if ((txn != nullptr) && (txn->m_state != TxnState::TXN_STATE_HOLD)) {
810  this->finishTransaction(txn, false);
811  status = Status::SUCCESS;
812  }
813 
814  return status;
815 }
816 
818  Class::T cfdp_class,
819  Keep::T keep,
820  U8 chan,
821  U8 priority,
822  EntityId dest_id) {
823  txn->initTxFile(cfdp_class, keep, chan, priority);
824 
825  // Increment sequence number for new transaction
826  ++this->m_seqNum;
827 
828  // Capture info for history
829  txn->m_history->seq_num = this->m_seqNum;
830  txn->m_history->src_eid = m_manager->getLocalEidParam();
831  txn->m_history->peer_eid = dest_id;
832 
833  txn->m_chan->insertSortPrio(txn, QueueId::PEND);
834 }
835 
836 Status::T Engine::txFile(const Fw::String& src_filename,
837  const Fw::String& dst_filename,
838  Class::T cfdp_class,
839  Keep::T keep,
840  U8 chan_num,
841  U8 priority,
842  EntityId dest_id,
843  TransactionInitType initType) {
844  Transaction* txn;
845  Channel* chan = nullptr;
846 
847  FW_ASSERT(chan_num < Cfdp::NumChannels, chan_num, Cfdp::NumChannels);
848  chan = m_channels[chan_num];
849 
851 
854  } else {
855  txn = nullptr;
856  }
857 
858  if (txn == nullptr) {
859  this->m_manager->log_WARNING_LO_MaxTxTransactionsReached();
860  ret = Cfdp::Status::ERROR;
861  } else {
862  // NOTE: the caller of this function ensures the provided src and dst filenames are nullptr terminated
863 
864  txn->m_history->fnames.src_filename = src_filename;
865  txn->m_history->fnames.dst_filename = dst_filename;
866  this->txFileInitiate(txn, cfdp_class, keep, chan_num, priority, dest_id);
867 
868  chan->incrementCmdTxCounter();
869  txn->m_flags.tx.cmd_tx = true;
870 
871  // Set transaction initiation type
872  txn->m_initType = initType;
873 
874  // Log transaction queued event
875  this->m_manager->log_ACTIVITY_LO_TxFileQueued(txn->m_history->fnames.src_filename, txn->m_history->seq_num);
876  }
877 
878  return ret;
879 }
880 
881 Transaction* Engine::startRxTransaction(U8 chan_num) {
882  Channel* chan = nullptr;
883  Transaction* txn;
884 
885  FW_ASSERT(chan_num < Cfdp::NumChannels, chan_num, Cfdp::NumChannels);
886  chan = m_channels[chan_num];
887 
888  // Bound concurrent receive transactions. The transaction pool is shared with commanded
889  // transmit work and sized for MaxSimultaneousRx receive transactions, so without this
890  // bound inbound traffic alone can consume every slot and block commanded transfers.
891  if (chan->getNumRx() < MaxSimultaneousRx) {
893  } else {
894  txn = nullptr;
895  }
896 
897  if (txn != nullptr) {
898  chan->incrementRxCounter();
899  // set default FIN status
902 
903  txn->m_flags.com.q_index = QueueId::RX;
904  chan->insertBackInQueue(static_cast<QueueId::T>(txn->m_flags.com.q_index), &txn->m_cl_node);
905  }
906 
907  return txn;
908 }
909 
911  const Fw::String& src_filename,
912  const Fw::String& dst_filename,
913  Class::T cfdp_class,
914  Keep::T keep,
915  U8 chan,
916  U8 priority,
917  EntityId dest_id) {
919  Os::Directory::Status dirStatus;
920 
921  // make sure the directory can be open
922  dirStatus = pb->dir.open(src_filename.toChar(), Os::Directory::READ);
923  if (dirStatus != Os::Directory::OP_OK) {
924  this->m_manager->log_WARNING_LO_PlaybackDirOpenFailed(src_filename, dirStatus);
925  this->m_manager->incrementFaultDirectoryRead(chan);
926  status = Cfdp::Status::ERROR;
927  } else {
928  pb->diropen = true;
929  pb->busy = true;
930  pb->keep = keep;
931  pb->priority = priority;
932  pb->dest_id = dest_id;
933  pb->cfdp_class = cfdp_class;
934 
935  // NOTE: the caller of this function ensures the provided src and dst filenames are nullptr terminated
936  pb->fnames.src_filename = src_filename;
937  pb->fnames.dst_filename = dst_filename;
938  }
939 
940  // the executor will start the transfer next cycle
941  return status;
942 }
943 
945  const Fw::String& dst_filename,
946  Class::T cfdp_class,
947  Keep::T keep,
948  U8 chan,
949  U8 priority,
950  EntityId dest_id) {
951  U32 i;
952  Playback* pb;
953  Status::T status;
954 
955  // Loop through the channel's playback directories to find an open slot
956  for (i = 0; i < MaxCommandedPlaybackDirectoriesPerChan; ++i) {
957  pb = m_channels[chan]->getPlayback(i);
958  if (!pb->busy) {
959  break;
960  }
961  }
962 
965  status = Cfdp::Status::ERROR;
966  } else {
967  status = this->playbackDirInitiate(pb, src_filename, dst_filename, cfdp_class, keep, chan, priority, dest_id);
968  }
969 
970  return status;
971 }
972 
974  U8 pollId,
975  const Fw::String& srcDir,
976  const Fw::String& dstDir,
977  Class::T cfdp_class,
978  U8 priority,
979  EntityId destEid,
980  U32 intervalSec) {
982  CfdpPollDir* pd = nullptr;
983 
984  FW_ASSERT(chanId < Cfdp::NumChannels, chanId, Cfdp::NumChannels);
986 
987  // First check if the poll directory is already in use
988  pd = m_channels[chanId]->getPollDir(pollId);
989  if (pd->enabled == Fw::Enabled::DISABLED) {
990  // Populate arguments
991  pd->intervalSec = intervalSec;
992  pd->priority = priority;
993  pd->cfdpClass = cfdp_class;
994  pd->destEid = destEid;
995  pd->srcDir = srcDir;
996  pd->dstDir = dstDir;
997 
998  // Set timer and enable polling
1001  } else {
1002  // Poll directory slot already in use
1003  this->m_manager->log_WARNING_LO_PollDirBusy(chanId, pollId);
1004  status = Cfdp::Status::ERROR;
1005  }
1006 
1007  return status;
1008 }
1009 
1012  CfdpPollDir* pd = nullptr;
1013 
1014  FW_ASSERT(chanId < Cfdp::NumChannels, chanId, Cfdp::NumChannels);
1016 
1017  // Check if the poll directory is in use
1018  pd = m_channels[chanId]->getPollDir(pollId);
1019  if (pd->enabled == Fw::Enabled::ENABLED) {
1020  // Clear poll directory arguments
1021  pd->intervalSec = 0;
1022  pd->priority = 0;
1023  pd->cfdpClass = static_cast<Class::T>(0);
1024  pd->destEid = static_cast<EntityId>(0);
1025  pd->srcDir = "";
1026  pd->dstDir = "";
1027 
1028  // Disable timer and polling
1031  } else {
1032  // Poll directory not active - cannot stop
1033  this->m_manager->log_WARNING_LO_PollDirNotActive(chanId, pollId);
1034  status = Cfdp::Status::ERROR;
1035  }
1036 
1037  return status;
1038 }
1039 
1040 void Engine::cycle(void) {
1041  U32 i;
1042 
1043  for (i = 0; i < Cfdp::NumChannels; ++i) {
1044  Channel* chan = m_channels[i];
1045  FW_ASSERT(chan != nullptr);
1046 
1047  chan->resetOutgoingCounter();
1048 
1049  if (chan->getFlowState() == Cfdp::Flow::NOT_FROZEN) {
1050  // handle ticks before tx cycle. Do this because there may be a limited number of TX messages available
1051  // this cycle, and it's important to respond to class 2 ACK/NAK more than it is to send new filedata
1052  // PDUs.
1053 
1054  // cycle all transactions (tick)
1055  chan->tickTransactions();
1056 
1057  // cycle the current tx transaction
1058  chan->cycleTx();
1059 
1061  chan->processPollingDirectories();
1062  }
1063  }
1064 }
1065 
1066 void Engine::finishTransaction(Transaction* txn, bool keep_history) {
1067  if (txn->m_flags.com.q_index == QueueId::FREE) {
1068  this->m_manager->log_DIAGNOSTIC_ResetFreedTransaction();
1069  return;
1070  }
1071 
1072  // A transaction in HOLD has already been finished and is waiting for its inactivity timer
1073  // to recycle it. Finishing it again would repeat the completion bookkeeping (the commanded
1074  // TX and playback counters, completion events, and the port notification), so do nothing.
1075  if (txn->m_state == TxnState::TXN_STATE_HOLD) {
1076  return;
1077  }
1078 
1079  // this should always be
1080  FW_ASSERT(txn->m_chan != nullptr);
1081 
1082  // If this was on the TXA queue (transmit side) then we need to move it out
1083  // so the tick processor will stop trying to actively transmit something -
1084  // it should move on to the next transaction.
1085  //
1086  // A TX transaction still waiting on PEND (queued behind another downlink, or held
1087  // because dequeue is disabled) must also be moved to TXW. PEND is never ticked, so
1088  // the inactivity timer armed below could never recycle it, and cycleTx would later
1089  // promote the HOLD transaction to TXA where dispatchTx has no handler for it and
1090  // cycleTxFirstActive would never leave its dispatch loop.
1091  //
1092  // RX transactions can stay on the RX queue, that does not hurt anything
1093  // because they are only triggered when a PDU comes in matching that seq_num
1094  // (RX queue is not separated into A/W parts)
1095  if (txn->m_flags.com.q_index == QueueId::TXA || txn->m_flags.com.q_index == QueueId::PEND) {
1096  txn->m_chan->dequeueTransaction(txn);
1097  txn->m_chan->insertSortPrio(txn, QueueId::TXW);
1098  }
1099 
1100  if (true == txn->m_fd.isOpen()) {
1101  txn->m_fd.close();
1102 
1103  if (!txn->m_keep) {
1104  this->handleNotKeepFile(txn);
1105  }
1106  }
1107 
1108  if (txn->m_history != nullptr) {
1109  // Emit completion events for successful transactions
1110  if (!TxnStatusIsError(txn->m_history->txn_stat)) {
1111  if (txn->m_history->dir == Direction::DIRECTION_TX) {
1112  this->m_manager->log_ACTIVITY_HI_TxFileTransferCompleted(
1113  txn->m_txn_class, txn->m_history->seq_num, txn->m_history->src_eid,
1114  txn->m_history->fnames.src_filename, txn->m_history->peer_eid, txn->m_history->fnames.dst_filename,
1115  static_cast<U32>(txn->m_fsize));
1116  } else if (txn->m_history->dir == Direction::DIRECTION_RX) {
1117  this->m_manager->log_ACTIVITY_HI_RxFileTransferCompleted(
1118  txn->m_txn_class, txn->m_history->seq_num, txn->m_history->src_eid,
1119  txn->m_history->fnames.src_filename, m_manager->getLocalEidParam(),
1120  txn->m_history->fnames.dst_filename, static_cast<U32>(txn->m_fsize));
1121  }
1122  } else {
1123  // Log failure events for failed transactions
1124  if (txn->m_history->dir == Direction::DIRECTION_TX) {
1125  this->m_manager->log_WARNING_LO_TxFileTransferFailed(
1126  txn->m_txn_class, txn->m_history->seq_num, txn->m_history->src_eid,
1127  txn->m_history->fnames.src_filename, txn->m_history->peer_eid, txn->m_history->fnames.dst_filename,
1128  static_cast<U8>(txn->m_history->txn_stat));
1129  } else if (txn->m_history->dir == Direction::DIRECTION_RX) {
1130  this->m_manager->log_WARNING_LO_RxFileTransferFailed(
1131  txn->m_txn_class, txn->m_history->seq_num, txn->m_history->src_eid,
1132  txn->m_history->fnames.src_filename, txn->m_history->peer_eid, txn->m_history->fnames.dst_filename,
1133  static_cast<U8>(txn->m_history->txn_stat));
1134  }
1135  }
1136 
1137  // extra bookkeeping for tx direction only
1138  if (txn->m_history->dir == Direction::DIRECTION_TX && txn->m_flags.tx.cmd_tx) {
1139  txn->m_chan->decrementCmdTxCounter();
1140  }
1141 
1142  // Notify via port if this was a port-initiated transfer
1143  if (txn->m_initType == TransactionInitType::INIT_BY_PORT) {
1144  // Map transaction status to SendFileStatus
1145  Svc::SendFileStatus::T status;
1146  if (TxnStatusIsError(txn->m_history->txn_stat)) {
1148  } else {
1150  }
1151 
1152  // Invoke the file complete notification
1153  this->m_manager->sendFileComplete(status);
1154  }
1155 
1156  txn->m_flags.com.keep_history = keep_history;
1157  }
1158 
1159  if (txn->m_pb) {
1160  // a playback's transaction is now done, decrement the playback counter
1161  FW_ASSERT(txn->m_pb->num_ts);
1162  --txn->m_pb->num_ts;
1163  }
1164 
1165  txn->m_chan->clearCurrentIfMatch(txn);
1166 
1167  // Put this transaction into the holdover state, inactivity timer will recycle it
1168  txn->m_state = TxnState::TXN_STATE_HOLD;
1169  this->armInactTimer(txn);
1170 }
1171 
1173  if (!TxnStatusIsError(txn->m_history->txn_stat)) {
1174  txn->m_history->txn_stat = txn_stat;
1175  }
1176 }
1177 
1178 void Engine::cancelTransaction(Transaction* txn) {
1179  void (Transaction::* fns[static_cast<U32>(Direction::DIRECTION_NUM)])() = {nullptr};
1180 
1181  fns[static_cast<U32>(Direction::DIRECTION_RX)] = &Transaction::rCancel;
1182  fns[static_cast<U32>(Direction::DIRECTION_TX)] = &Transaction::sCancel;
1183 
1184  if (!txn->m_flags.com.canceled) {
1185  txn->m_flags.com.canceled = true;
1187 
1188  // this should always be true, just confirming before indexing into array
1189  if (txn->m_history->dir < Direction::DIRECTION_NUM) {
1190  (txn->*fns[static_cast<U32>(txn->m_history->dir)])();
1191  }
1192  }
1193 }
1194 
1195 bool Engine::isPollingDir(const Fw::StringBase& src_file, U8 chan_num) {
1196  bool return_code = false;
1197  Fw::String src_dir;
1198  CfdpPollDir* pd;
1199  U32 i;
1200 
1201  // Extract directory portion (everything before last '/')
1202  FwSizeType lastSlashPos = 0;
1203  bool foundSlash = false;
1204  for (FwSizeType pos = 0; pos < src_file.length(); ++pos) {
1205  if (src_file.toChar()[pos] == '/') {
1206  lastSlashPos = pos;
1207  foundSlash = true;
1208  }
1209  }
1210 
1211  if (foundSlash) {
1212  src_dir.format("%.*s", static_cast<int>(lastSlashPos), src_file.toChar());
1213  }
1214 
1215  for (i = 0; i < MaxPollingDirPerChan; ++i) {
1216  pd = m_channels[chan_num]->getPollDir(i);
1217  if (src_dir == pd->srcDir) {
1218  return_code = true;
1219  break;
1220  }
1221  }
1222 
1223  return return_code;
1224 }
1225 
1226 void Engine::handleNotKeepFile(Transaction* txn) {
1228  Fw::String failDir;
1229  Fw::String moveDir;
1230 
1231  // Sender
1232  if (txn->getHistory()->dir == Direction::DIRECTION_TX) {
1233  if (!TxnStatusIsError(txn->getHistory()->txn_stat)) {
1234  // If move directory is defined attempt move
1235  moveDir = m_manager->getMoveDirParam(txn->getChannelId());
1236  if (moveDir.length() > 0) {
1237  fileStatus = Os::FileSystem::moveFile(txn->m_history->fnames.src_filename.toChar(), moveDir.toChar());
1238  if (fileStatus != Os::FileSystem::OP_OK) {
1239  m_manager->log_WARNING_LO_FailKeepFileMove(txn->m_history->fnames.src_filename, moveDir,
1240  fileStatus);
1241  }
1242  }
1243 
1244  // If move_dir is empty or move failed, delete the file
1245  if (fileStatus != Os::FileSystem::OP_OK) {
1246  fileStatus = Os::FileSystem::removeFile(txn->m_history->fnames.src_filename.toChar());
1247  if (fileStatus != Os::FileSystem::OP_OK) {
1248  m_manager->log_WARNING_LO_FileRemoveFailed(txn->m_history->fnames.src_filename, fileStatus);
1249  }
1250  }
1251  } else {
1252  // file inside a polling directory
1253  if (this->isPollingDir(txn->m_history->fnames.src_filename, txn->getChannelId())) {
1254  // If fail directory is defined attempt move
1255  failDir = m_manager->getFailDirParam(txn->getChannelId());
1256  if (failDir.length() > 0) {
1257  fileStatus =
1258  Os::FileSystem::moveFile(txn->m_history->fnames.src_filename.toChar(), failDir.toChar());
1259  if (fileStatus != Os::FileSystem::OP_OK) {
1260  m_manager->log_WARNING_LO_FailPollFileMove(txn->m_history->fnames.src_filename, failDir,
1261  fileStatus);
1262  }
1263  }
1264 
1265  // If fail_dir is empty or move failed, delete the file
1266  if (fileStatus != Os::FileSystem::OP_OK) {
1267  fileStatus = Os::FileSystem::removeFile(txn->m_history->fnames.src_filename.toChar());
1268  if (fileStatus != Os::FileSystem::OP_OK) {
1269  m_manager->log_WARNING_LO_FileRemoveFailed(txn->m_history->fnames.src_filename, fileStatus);
1270  }
1271  }
1272  }
1273  }
1274  }
1275  // Not Sender
1276  else {
1277  fileStatus = Os::FileSystem::removeFile(txn->m_history->fnames.dst_filename.toChar());
1278  if (fileStatus != Os::FileSystem::OP_OK) {
1279  m_manager->log_WARNING_LO_FileRemoveFailed(txn->m_history->fnames.dst_filename, fileStatus);
1280  }
1281  }
1282 }
1283 
1285  return this->m_manager->getChannelTelemetryRef(channelId);
1286 }
1287 
1288 } // namespace Cfdp
1289 } // namespace Ccsds
1290 } // namespace Svc
void incrementSentPdu(U8 chanId)
Increment sent PDU counter.
Status::T recvFd(Transaction *txn, const FileDataPdu &pdu)
Unpack a file data PDU from a received message.
Definition: Engine.cpp:472
Serialization/Deserialization operation was successful.
CfdpTxnFilenames fnames
file names associated with this history entry
Definition: Types.hpp:245
void s1Recv(const Fw::Buffer &buffer)
S1 receive PDU processing.
Status::T sendEof(Transaction *txn)
Create, encode, and send an EOF (End of File) PDU.
Definition: Engine.cpp:227
TransactionInitType
Transaction initiation method.
Definition: Types.hpp:165
void sendFileComplete(Svc::SendFileStatus::T status)
void incrementRecvErrors(U8 chanId)
Increment receive error counter.
Fw::String dstDir
path to destination dir
Definition: Types.hpp:309
U8 getChannelId() const
Get the channel ID.
Definition: Channel.hpp:178
Status::T txFile(const Fw::String &src, const Fw::String &dst, Class::T cfdp_class, Keep::T keep, U8 chan_num, U8 priority, EntityId dest_id, TransactionInitType initType=TransactionInitType::INIT_BY_COMMAND)
Begin transmit of a file.
Definition: Engine.cpp:836
CFDP Channel class.
Definition: Channel.hpp:56
virtual void * allocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t))=0
Status::T stopPollDir(U8 chanId, U8 pollId)
Stop polling a directory.
Definition: Engine.cpp:1010
A variable-length serializable buffer.
~Channel()
Destruct a Channel.
Definition: Channel.cpp:169
Status::T recvMd(Transaction *txn, const MetadataPdu &pdu)
Handle receipt of metadata PDU.
Definition: Engine.cpp:442
Fw::String getRxDirParam(U8 channelIndex)
void log_WARNING_LO_FailPollFileMove(const Fw::StringBase &srcFile, const Fw::StringBase &failDir, I32 status) const
Log event FailPollFileMove.
EntityId getDestEid() const
Get the destination entity ID.
Definition: PduHeader.hpp:133
CFDP Transaction state machine class.
Status::T cancelTransactionBySeq(U8 channelId, TransactionSeq transactionSeq, EntityId entityId)
Cancel a transaction with graceful close-out.
Definition: Engine.cpp:783
PlatformSizeType FwSizeType
static Status moveFile(const char *sourcePath, const char *destPath)
Move a file from sourcePath to destPath.
Definition: FileSystem.cpp:209
I32 FwEnumStoreType
void setSize(FwSizeType size)
Definition: Buffer.cpp:131
Enabled state.
U16 num_ts
number of transactions
Definition: Types.hpp:282
void init(Fw::MemAllocator &allocator, FwEnumStoreType memId)
Initialize the CFDP engine.
Definition: Engine.cpp:89
State assigned to a newly allocated transaction object.
void rCancel()
Cancel an R transaction.
void initialize(PduDirection direction, Cfdp::Class::T txmMode, EntityId sourceEid, TransactionSeq transactionSeq, EntityId destEid, ConditionCode conditionCode, U32 checksum, FileSize fileSize)
Initialize an EOF PDU.
Definition: EofPdu.cpp:14
bool cmd_tx
indicates transaction is commanded (ground) tx
Definition: Types.hpp:395
U32 EntityId
Entity id size.
first one on this list is active
void r2Recv(const Fw::Buffer &buffer)
R2 receive PDU processing.
void initialize(PduDirection direction, Cfdp::Class::T txmMode, EntityId sourceEid, TransactionSeq transactionSeq, EntityId destEid, FileDirective directiveCode, U8 directiveSubtypeCode, ConditionCode conditionCode, AckTxnStatus transactionStatus)
Initialize an ACK PDU.
Definition: AckPdu.cpp:14
void log_WARNING_LO_InvalidDestinationEid(U32 destEid) const
Log event InvalidDestinationEid.
void s2Tx()
S2 dispatch function.
void disableTimer(void)
Disables a CFDP timer.
Definition: Timer.cpp:30
void log_WARNING_LO_TxFileTransferFailed(const Svc::Ccsds::Cfdp::Class &cfdpClass, U32 seqNum, U32 srcEid, const Fw::StringBase &srcFile, U32 destEid, const Fw::StringBase &destFile, U8 conditionCode) const
Log event TxFileTransferFailed.
List of TLVs.
Definition: Tlv.hpp:88
ConditionCode getConditionCode() const
Get condition code.
Definition: FinPdu.hpp:65
bool hasSegmentMetadata() const
Check if segment metadata is present.
Definition: PduHeader.hpp:145
U8 * getData() const
Definition: Buffer.cpp:82
bool appendTlv(const Tlv &tlv)
Definition: FinPdu.hpp:78
U8 priority
priority to use when placing transactions on the pending queue
Definition: Types.hpp:304
virtual const CHAR * toChar() const =0
Convert to a C-style char*.
void log_WARNING_LO_ChunklistUnavailable(U32 transactionSeq) const
Log event ChunklistUnavailable.
Status checkContainment(const char *resolvedPath, const char *allowedDirectory)
Check whether an already-resolved path is within an allowed directory.
FileSize getFileSize() const
Get the file size.
Definition: MetadataPdu.hpp:73
TlvType getType() const
Definition: Tlv.cpp:69
Fw::String getFailDirParam(U8 channelIndex)
void abandonInitTransaction(Transaction *txn)
Definition: Engine.cpp:675
const Tlv & getTlv(U8 index) const
Definition: Tlv.cpp:206
Deserialization data had incorrect values (unexpected data types)
void incrementFaultDirectoryRead(U8 chanId)
Increment fault directory read counter.
T
The raw enum type.
CFDP class 2 - Reliable transfer (Acknowledged)
Definition: ClassEnumAc.hpp:44
const Fw::String & getDestFilename() const
Get the destination filename.
Definition: MetadataPdu.hpp:79
CFDP class 1 - Unreliable transfer (Unacknowledged)
Definition: ClassEnumAc.hpp:46
Status::T sendAck(Transaction *txn, AckTxnStatus ts, FileDirective dir_code, ConditionCode cc, EntityId peer_eid, TransactionSeq tsn)
Create, encode, and send an ACK (Acknowledgment) PDU.
Definition: Engine.cpp:262
void incrementRecvDropped(U8 chanId)
Increment receive dropped counter.
void processPollingDirectories()
Process all polling directories for this channel.
Definition: Channel.cpp:353
void sendPduBuffer(Channel &channel, Fw::Buffer &pduBuffer)
U32 intervalSec
number of seconds to wait before trying a new directory
Definition: Types.hpp:302
TxnStatus
Values for Transaction Status code.
Definition: Types.hpp:193
Status::T startPollDir(U8 chanId, U8 pollId, const Fw::String &srcDir, const Fw::String &dstDir, Class::T cfdp_class, U8 priority, EntityId destEid, U32 intervalSec)
Start polling a directory.
Definition: Engine.cpp:973
void s2Recv(const Fw::Buffer &buffer)
S2 receive PDU processing.
void log_ACTIVITY_HI_TxFileTransferCompleted(const Svc::Ccsds::Cfdp::Class &cfdpClass, U32 seqNum, U32 srcEid, const Fw::StringBase &srcFile, U32 destEid, const Fw::StringBase &destFile, U32 fileSize) const
Log event TxFileTransferCompleted.
CFDP Playback entry.
Definition: Types.hpp:278
bool appendTlv(const Tlv &tlv)
Definition: EofPdu.hpp:75
void incrementCmdTxCounter()
Increment the command TX counter for this channel.
Definition: Channel.hpp:207
void log_WARNING_HI_RxDestPathRejected(U8 channelId, U32 srcEid, U32 seqNum, const Fw::StringBase &filename, const Fw::StringBase &rxDir, const Svc::Ccsds::Cfdp::RxDestPathRejectReason &reason) const
const Fw::String & getSourceFilename() const
Get the source filename.
Definition: MetadataPdu.hpp:76
Fw::SerializeStatus fromSerialBuffer(Fw::SerialBufferBase &serialBuffer)
Initialize this Header from a SerialBufferBase.
Definition: PduHeader.cpp:178
SerializeStatus
forward declaration for string
Status resolveDirectoryFromCwd(const char *path, char *resolvedOut, FwSizeType resolvedSize)
Resolve a directory path from CWD into the form checkContainment expects.
void incrementRecvSpurious(U8 chanId)
Increment receive spurious counter.
void log_ACTIVITY_LO_MetadataReceived(const Fw::StringBase &srcFile, const Fw::StringBase &destFile, U32 transactionSeq) const
Log event MetadataReceived.
void finishTransaction(Transaction *txn, bool keep_history)
Finish a transaction.
Definition: Engine.cpp:1066
U32 TransactionSeq
transaction sequence number size
Flow::T getFlowState() const
Get the flow state for this channel.
Definition: Channel.hpp:260
void returnPduBuffer(Channel &channel, Fw::Buffer &pduBuffer)
State assigned to a transaction after freeing it.
void log_WARNING_LO_MaxTxTransactionsReached() const
Log event MaxTxTransactionsReached.
U8 getChannelId() const
Get channel ID.
U8 getNumTlv() const
Definition: Tlv.cpp:202
bool keep_history
whether history should be preserved during recycle
Definition: Types.hpp:365
T
The raw enum type.
Definition: KeepEnumAc.hpp:36
U32 getNumRx() const
Get the number of receive transactions currently holding a slot.
Definition: Channel.hpp:219
void cycleTx()
Cycle the TX side of this channel.
Definition: Channel.cpp:213
virtual ~Engine()
Destroy the Engine object.
Definition: Engine.cpp:67
The type of a File Data PDU.
Definition: FileDataPdu.hpp:19
void setChannelFlowState(U8 channelId, Flow::T flowState)
Set channel flow state.
Definition: Engine.cpp:759
Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase &buffer, Fw::Endianness mode=Fw::Endianness::BIG) override
Fw::Serializable interface - deserialize from buffer.
Definition: FinPdu.cpp:50
Status::T sendNak(Transaction *txn, NakPdu &nakPdu)
Encode and send a NAK (Negative Acknowledgment) PDU.
Definition: Engine.cpp:332
Engine(CfdpManager *manager)
Construct a new Engine object.
Definition: Engine.cpp:61
Status::T getPduBuffer(Fw::Buffer &buffer, Channel &channel, FwSizeType size)
void log_WARNING_LO_FileDataSegmentMetadata() const
Log event FileDataSegmentMetadata.
bool validateRxDestPath(U8 chan_num, Fw::String &path, RxDestPathRejectReason &reason)
Validate and canonicalize a received destination path against the channel rx_dir. ...
Definition: Engine.cpp:405
void incrementFaultFileOpen(U8 chanId)
Increment fault file open counter.
void resetOutgoingCounter()
Reset the outgoing PDU counter to zero.
Definition: Channel.hpp:195
void incrementRxCounter()
Increment the receive transaction counter for this channel.
Definition: Channel.hpp:224
virtual Status::T sendMd(Transaction *txn)
Create, encode, and send a Metadata PDU.
Definition: Engine.cpp:189
void receivePdu(U8 chan_id, const Fw::Buffer &buffer)
Receive and process a PDU.
Definition: Engine.cpp:685
void log_WARNING_LO_RxFileTransferFailed(const Svc::Ccsds::Cfdp::Class &cfdpClass, U32 seqNum, U32 srcEid, const Fw::StringBase &srcFile, U32 destEid, const Fw::StringBase &destFile, U8 conditionCode) const
Log event RxFileTransferFailed.
static constexpr FwSizeType MAX_PATH_LENGTH
Maximum supported path length for resolution buffers.
Status::T recvNak(Transaction *txn, const NakPdu &pdu)
Unpack a NAK PDU from a received message.
Definition: Engine.cpp:524
void armInactTimer(Transaction *txn)
Arm the inactivity timer for a transaction.
Definition: Engine.cpp:110
void clearCurrentIfMatch(Transaction *txn)
Check if current transaction matches and clear if so.
Definition: Channel.cpp:709
ConditionCode TxnStatusToConditionCode(TxnStatus txn_stat)
Converts the internal transaction status to a CFDP condition code.
Definition: Utils.cpp:120
History * getHistory() const
Get transaction history.
void s1Tx()
S1 dispatch function.
void tickTransactions()
Tick all transactions on this channel.
Definition: Channel.cpp:269
Direction dir
direction of this history entry
Definition: Types.hpp:247
The type of a Metadata PDU.
Definition: MetadataPdu.hpp:20
void dequeueTransaction(Transaction *txn)
Free a transaction from the queue it&#39;s on.
Definition: Channel.cpp:503
Single TLV entry.
Definition: Tlv.hpp:59
The type of a Finished PDU.
Definition: FinPdu.hpp:19
void dispatchTx(Transaction *txn)
Dispatch TX state machine for a transaction.
Definition: Engine.cpp:174
void setTimer(U32 timerDuration)
Definition: Timer.cpp:25
U16 getDataSize() const
Get the data size.
Definition: FileDataPdu.hpp:68
void incrementRecvPdu(U8 chanId)
Increment received PDU counter.
void txFileInitiate(Transaction *txn, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Initiate a file transfer transaction.
Definition: Engine.cpp:817
void setTxnStatus(Transaction *txn, TxnStatus txn_stat)
Helper function to store transaction status code only.
Definition: Engine.cpp:1172
void close() override
close the file, if not opened then do nothing
Definition: File.cpp:97
Generic CFDP error return code.
const TlvList & getTlvList() const
Get TLV list.
Definition: EofPdu.hpp:78
Status::T sendFd(Transaction *txn, FileDataPdu &fdPdu)
Encode and send a File Data PDU.
Definition: Engine.cpp:219
void incrementSentEofCanceled(U8 chanId)
Increment sent EOF canceled counter.
const char * toChar() const
Convert to a C-style char*.
void addSentFileDataBytes(U8 chanId, U32 bytes)
Add sent file data bytes.
U32 getValue() const
Get the checksum value.
Definition: Checksum.cpp:45
Status::T playbackDirInitiate(Playback *pb, const Fw::String &src_filename, const Fw::String &dst_filename, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Initiate playback of a directory.
Definition: Engine.cpp:910
Fw::String srcDir
path to source dir
Definition: Types.hpp:308
const TlvList & getTlvList() const
Get TLV list.
Definition: FinPdu.hpp:81
void decrementCmdTxCounter()
Decrement the command TX counter for this channel.
Definition: Channel.cpp:699
FormatStatus format(const CHAR *formatString,...)
write formatted string to buffer
Definition: StringBase.cpp:58
void log_WARNING_LO_RxTransactionLimitReached(U32 srcEid, U32 transactionSeq) const
Log event RxTransactionLimitReached.
void log_WARNING_LO_FailKeepFileMove(const Fw::StringBase &srcFile, const Fw::StringBase &moveDir, I32 status) const
Log event FailKeepFileMove.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
SerializeStatus setBuffLen(Serializable::SizeType length) override
Set buffer length manually.
void processPlaybackDirectories()
Process all playback directories for this channel.
Definition: Channel.cpp:336
CFDP operation has been successful.
void insertSortPrio(Transaction *txn, QueueId::T queue)
Insert a transaction into a priority sorted transaction queue.
Definition: Channel.cpp:668
FwSizeType getSize() const
Definition: Buffer.cpp:90
U32 getAckTimerParam(U8 channelIndex)
CfdpTxnFilenames fnames
Definition: Types.hpp:281
Path is valid and within the allowed directory.
Cfdp::ChannelTelemetry & getChannelTelemetryRef(U8 channelId)
Get reference to channel telemetry for Channel class.
Definition: Engine.cpp:1284
U32 getInactivityTimerParam(U8 channelIndex)
State where all PDUs are dropped.
Transaction * findUnusedTransaction(Direction direction)
Find an unused transaction on this channel.
Definition: Channel.cpp:396
Class::T getClass() const
Get transaction class (CLASS_1 or CLASS_2)
static constexpr FwSizeType PACKET_DESCRIPTOR_SIZE
Size of packet descriptor prepended to PDUs for ComQueue.
Definition: CfdpManager.hpp:67
TransactionSeq seq_num
transaction identifier, stays constant for entire transfer
Definition: Types.hpp:251
other OS-specific error
Definition: FileSystem.hpp:40
void initTxFile(Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority)
Initialize transaction for outgoing file transfer.
The configured rx_dir could not be resolved (for example, CWD unavailable) or is too long...
void initialize(PduDirection direction, Cfdp::Class::T txmMode, EntityId sourceEid, TransactionSeq transactionSeq, EntityId destEid, ConditionCode conditionCode, FinDeliveryCode deliveryCode, FinFileStatus fileStatus)
Initialize a Finished PDU.
Definition: FinPdu.cpp:14
void cycle()
Cycle the engine once per scheduler call.
Definition: Engine.cpp:1040
void cleanup(Fw::MemAllocator &allocator, FwEnumStoreType memId)
Clean up dynamically allocated resources.
Definition: Channel.cpp:174
Memory Allocation base class.
CFDP channel operations are executing nominally.
Definition: FlowEnumAc.hpp:37
The received path could not be resolved against rx_dir, or the joined path is too long to resolve...
void log_ACTIVITY_LO_TxFileQueued(const Fw::StringBase &sourceFileName, U32 transactionSeq) const
Log event TxFileQueued.
void log_WARNING_LO_PlaybackDirSlotUnavailable() const
Log event PlaybackDirSlotUnavailable.
void insertBackInQueue(QueueId::T queueidx, CListNode *node)
Insert a node at the back of a channel queue.
Definition: Channel.hpp:546
void log_WARNING_LO_UnhandledPduInIdleState() const
Log event UnhandledPduInIdleState.
Class::T cfdpClass
the CFDP class to send
Definition: Types.hpp:305
Status::T recvFin(Transaction *txn, const FinPdu &pdu)
Unpack an FIN PDU from a received message.
Definition: Engine.cpp:507
Operation was successful.
Definition: Directory.hpp:22
The type of a PDU header (common to all PDUs)
Definition: PduHeader.hpp:47
PduTypeEnum::T peekPduType(const Fw::Buffer &buffer)
Definition: PduHeader.cpp:253
Transaction initiated via port interface.
void sCancel()
Cancel an S transaction.
Fw::Enabled enabled
Enabled flag.
Definition: Types.hpp:311
void log_WARNING_LO_FailPduSerialization(U8 channelId, const Svc::Ccsds::Cfdp::PduTypeEnum &pduType, I32 status) const
Log event FailPduSerialization.
void incrementFaultTxEofError(U8 chanId)
Increment sent EOF error counter (any condition code that is not no-error or cancel) ...
void log_ACTIVITY_HI_RxFileTransferCompleted(const Svc::Ccsds::Cfdp::Class &cfdpClass, U32 seqNum, U32 srcEid, const Fw::StringBase &srcFile, U32 destEid, const Fw::StringBase &destFile, U32 fileSize) const
Log event RxFileTransferCompleted.
CfdpFlagsTx tx
applies to only send file transactions
Definition: Types.hpp:404
Status open(const char *path, OpenMode mode) override
Open or create a directory.
Definition: Directory.cpp:31
Transaction * findTransactionBySequenceNumber(TransactionSeq transaction_sequence_number, EntityId src_eid)
Finds an active transaction by sequence number.
Definition: Channel.cpp:457
TransactionSeq getTransactionSeq() const
Get the transaction sequence number.
Definition: PduHeader.hpp:130
Timer intervalTimer
Timer object used to poll the directory.
Definition: Types.hpp:300
Structure for the telemetry array of CFDP channels.
RateGroupDivider component implementation.
CfdpPollDir * getPollDir(U32 index)
Get a polling directory entry.
Definition: Channel.hpp:279
virtual SizeType length() const
Get the length of the string.
EntityId getSourceEid() const
Get the source entity ID.
Definition: PduHeader.hpp:127
U32 getNumCmdTx() const
Get the number of commanded TX transactions.
Definition: Channel.hpp:202
CfdpFlagsCommon com
applies to all transactions
Definition: Types.hpp:402
Status::T setSuspendResumeTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId, SuspendResume::T action)
Set transaction suspend state.
Definition: Engine.cpp:764
TxnStatus txn_stat
final status of operation
Definition: Types.hpp:248
Why a received Metadata PDU destination path was rejected by the channel rx_dir check.
Operation was successful.
Definition: FileSystem.hpp:24
void log_WARNING_LO_FileRemoveFailed(const Fw::StringBase &filename, I32 status) const
Log event FileRemoveFailed.
void txStateDispatch(const TxnSendDispatchTable *dispatch)
Top-level Dispatch function to send a PDU based on current state.
void log_WARNING_LO_PlaybackDirOpenFailed(const Fw::StringBase &directory, I32 status) const
Log event PlaybackDirOpenFailed.
EntityId src_eid
the source eid of the transaction
Definition: Types.hpp:249
Fw::String getMoveDirParam(U8 channelIndex)
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
Directory poll entry.
Definition: Types.hpp:298
A table of transmit handler functions based on transaction state.
Definition: Transaction.hpp:92
The type of an EOF PDU.
Definition: EofPdu.hpp:19
Status::T sendFin(Transaction *txn, FinDeliveryCode dc, FinFileStatus fs, ConditionCode cc)
Create, encode, and send a FIN (Finished) PDU.
Definition: Engine.cpp:305
Cfdp::ChannelTelemetry & getChannelTelemetryRef(U8 chanId)
Get reference to channel telemetry for queue depth updates.
void log_WARNING_LO_PollDirNotActive(U8 channelId, U8 pollId) const
Log event PollDirNotActive.
Status::T abandonTransaction(U8 channelId, TransactionSeq transactionSeq, EntityId entityId)
Abandon a transaction immediately.
Definition: Engine.cpp:799
void initialize(PduDirection direction, Cfdp::Class::T txmMode, EntityId sourceEid, TransactionSeq transactionSeq, EntityId destEid, FileSize fileSize, const Fw::String &sourceFilename, const Fw::String &destFilename, ChecksumType checksumType, U8 closureRequested)
Initialize a Metadata PDU.
Definition: MetadataPdu.cpp:16
void log_WARNING_LO_FailPduHeaderDeserialization(U8 channelId, I32 status) const
Log event FailPduHeaderDeserialization.
CfdpRxStateData receive
applies to only receive file transactions
Definition: Types.hpp:412
void log_DIAGNOSTIC_ResetFreedTransaction() const
Log event ResetFreedTransaction.
EntityId destEid
destination entity id
Definition: Types.hpp:306
U8 q_index
Q index this is in.
Definition: Types.hpp:359
AckTxnStatus GetTxnStatus(Transaction *txn)
Gets the status of this transaction.
Definition: Utils.cpp:43
T
The raw enum type.
Definition: ClassEnumAc.hpp:42
void log_WARNING_LO_PollDirBusy(U8 channelId, U8 pollId) const
Log event PollDirBusy.
T
The raw enum type.
Definition: FlowEnumAc.hpp:35
The type of a NAK PDU.
Definition: NakPdu.hpp:24
void setFlowState(Flow::T flowState)
Set the flow state for this channel.
Definition: Channel.hpp:253
Status resolvePath(const char *path, const char *baseDir, char *resolvedOut, FwSizeType resolvedSize)
Resolve a path by collapsing . and .. segments.
void armAckTimer(Transaction *txn)
Arm the ACK timer for a transaction.
Definition: Engine.cpp:105
void recycleTransaction(Transaction *txn)
Recover resources associated with a transaction.
Definition: Channel.cpp:620
Status::T playbackDir(const Fw::String &src, const Fw::String &dst, Class::T cfdp_class, Keep::T keep, U8 chan, U8 priority, EntityId dest_id)
Begin transmit of a directory.
Definition: Engine.cpp:944
void log_DIAGNOSTIC_TxLateFinAcked(Svc::Ccsds::Cfdp::EntityId srcEid, Svc::Ccsds::Cfdp::TransactionSeq seqNum) const
const PduHeader & asHeader() const
Get this as a Header.
Definition: FileDataPdu.hpp:62
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Disabled state.
static Status removeFile(const char *path)
Remove a file at the specified path.
Definition: FileSystem.cpp:87
bool isOpen() const
determine if the file is open
Definition: File.cpp:105
bool TxnStatusIsError(TxnStatus txn_stat)
Check if the internal transaction status represents an error.
Definition: Utils.cpp:113
Playback * getPlayback(U32 index)
Get a playback directory entry.
Definition: Channel.hpp:268
void r1Recv(const Fw::Buffer &buffer)
R1 receive PDU processing.
Error if directory doesn&#39;t exist.
Definition: Directory.hpp:36
void initialize(EntityId eid)
Definition: Tlv.cpp:59
void log_WARNING_LO_FailFinPduDeserialization(U8 channelId, I32 status) const
Log event FailFinPduDeserialization.
The type of an ACK PDU.
Definition: AckPdu.hpp:18
FwSizeType string_length(const CHAR *source, FwSizeType buffer_size)
get the length of the source string
Definition: StringUtils.cpp:32
EntityId peer_eid
peer_eid is always the "other guy", same src_eid for RX
Definition: Types.hpp:250
void log_WARNING_LO_FailMetadataPduDeserialization(U8 channelId, I32 status) const
Log event FailMetadataPduDeserialization.
Status::T recvEof(Transaction *txn, const EofPdu &pdu)
Unpack an EOF PDU from a received message.
Definition: Engine.cpp:490