GCC Code Coverage Report


Directory: ./
File: Svc/Ccsds/CfdpManager/Types/Types.hpp
Date: 2026-09-03 22:12:29
Exec Total Coverage
Lines: 0 1 0.0%
Functions: 0 1 0.0%
Branches: 0 0 -%

Line Branch Exec Source
1 // ======================================================================
2 // \title Types.hpp
3 // \author Brian Campuzano
4 // \brief hpp file for shared CFDP protocol type definitions
5 // ======================================================================
6
7 #ifndef Svc_Ccsds_Cfdp_Types_HPP
8 #define Svc_Ccsds_Cfdp_Types_HPP
9
10 #include <Fw/FPrimeBasicTypes.hpp>
11 #include <Fw/Types/EnabledEnumAc.hpp>
12 #include <Fw/Types/String.hpp>
13 #include <Fw/Types/StringTemplate.hpp>
14 #include <Os/Directory.hpp>
15 #include <Os/File.hpp>
16 #include <config/CfdpCfg.hpp>
17 #include <config/EntityIdAliasAc.hpp>
18 #include <config/FileSizeAliasAc.hpp>
19 #include <config/TransactionSeqAliasAc.hpp>
20
21 #include <CFDP/Checksum/Checksum.hpp>
22 #include <Svc/Ccsds/CfdpManager/Chunk.hpp>
23 #include <Svc/Ccsds/CfdpManager/Clist.hpp>
24 #include <Svc/Ccsds/CfdpManager/Timer.hpp>
25 #include <Svc/Ccsds/CfdpManager/Types/ClassEnumAc.hpp>
26 #include <Svc/Ccsds/CfdpManager/Types/FlowEnumAc.hpp>
27 #include <Svc/Ccsds/CfdpManager/Types/KeepEnumAc.hpp>
28 #include <Svc/Ccsds/CfdpManager/Types/QueueIdEnumAc.hpp>
29 #include <Svc/Ccsds/CfdpManager/Types/StatusEnumAc.hpp>
30 #include <Svc/Ccsds/CfdpManager/Types/SuspendResumeEnumAc.hpp>
31
32 namespace Svc {
33 namespace Ccsds {
34 namespace Cfdp {
35
36 // Forward declarations for class types used in structs below
37 class Transaction;
38
39 /**
40 * @brief Maximum possible number of transactions that may exist on a single CFDP channel
41 */
42 static constexpr U32 CFDP_NUM_TRANSACTIONS_PER_CHANNEL =
43 (MaxCommandedPlaybackFilesPerChan + MaxSimultaneousRx +
44 ((MaxPollingDirPerChan + MaxCommandedPlaybackDirectoriesPerChan) * NumTransactionsPerPlayback));
45
46 // CFDP File Directive Codes
47 // Blue Book section 5.2, table 5-4
48 enum class FileDirective : U8 {
49 FILE_DIRECTIVE_INVALID_MIN = 0, // Minimum used to limit range
50 FILE_DIRECTIVE_END_OF_FILE = 4, // End of File
51 FILE_DIRECTIVE_FIN = 5, // Finished
52 FILE_DIRECTIVE_ACK = 6, // Acknowledge
53 FILE_DIRECTIVE_METADATA = 7, // Metadata
54 FILE_DIRECTIVE_NAK = 8, // Negative Acknowledge
55 FILE_DIRECTIVE_PROMPT = 9, // Prompt
56 FILE_DIRECTIVE_KEEP_ALIVE = 12, // Keep Alive
57 FILE_DIRECTIVE_INVALID_MAX = 13 // Maximum used to limit range
58 };
59
60 // CFDP Condition Codes
61 // Blue Book section 5.2.2, table 5-5
62 enum class ConditionCode : U8 {
63 CONDITION_CODE_NO_ERROR = 0,
64 CONDITION_CODE_POS_ACK_LIMIT_REACHED = 1,
65 CONDITION_CODE_KEEP_ALIVE_LIMIT_REACHED = 2,
66 CONDITION_CODE_INVALID_TRANSMISSION_MODE = 3,
67 CONDITION_CODE_FILESTORE_REJECTION = 4,
68 CONDITION_CODE_FILE_CHECKSUM_FAILURE = 5,
69 CONDITION_CODE_FILE_SIZE_ERROR = 6,
70 CONDITION_CODE_NAK_LIMIT_REACHED = 7,
71 CONDITION_CODE_INACTIVITY_DETECTED = 8,
72 CONDITION_CODE_INVALID_FILE_STRUCTURE = 9,
73 CONDITION_CODE_CHECK_LIMIT_REACHED = 10,
74 CONDITION_CODE_UNSUPPORTED_CHECKSUM_TYPE = 11,
75 CONDITION_CODE_SUSPEND_REQUEST_RECEIVED = 14,
76 CONDITION_CODE_CANCEL_REQUEST_RECEIVED = 15
77 };
78
79 // CFDP ACK Transaction Status
80 // Blue Book section 5.2.4, table 5-8
81 enum class AckTxnStatus : U8 {
82 ACK_TXN_STATUS_UNDEFINED = 0,
83 ACK_TXN_STATUS_ACTIVE = 1,
84 ACK_TXN_STATUS_TERMINATED = 2,
85 ACK_TXN_STATUS_UNRECOGNIZED = 3,
86 ACK_TXN_STATUS_INVALID = 4
87 };
88
89 // CFDP FIN Delivery Code
90 // Blue Book section 5.2.3, table 5-7
91 enum class FinDeliveryCode : U8 {
92 FIN_DELIVERY_CODE_COMPLETE = 0, // Data complete
93 FIN_DELIVERY_CODE_INCOMPLETE = 1 // Data incomplete
94 };
95
96 // CFDP FIN File Status
97 // Blue Book section 5.2.3, table 5-7
98 enum class FinFileStatus : U8 {
99 FIN_FILE_STATUS_DISCARDED = 0, // File discarded deliberately
100 FIN_FILE_STATUS_DISCARDED_FILESTORE = 1, // File discarded due to filestore rejection
101 FIN_FILE_STATUS_RETAINED = 2, // File retained successfully
102 FIN_FILE_STATUS_UNREPORTED = 3 // File status unreported
103 };
104
105 // CFDP Checksum Type
106 // Blue Book section 5.2.5, table 5-9
107 enum class ChecksumType : U8 {
108 CHECKSUM_TYPE_MODULAR = 0, // Modular checksum
109 CHECKSUM_TYPE_CRC_32 = 1, // CRC-32 (not currently supported)
110 CHECKSUM_TYPE_NULL_CHECKSUM = 15 // Null checksum
111 };
112
113 /**
114 * @brief High-level state of a transaction
115 */
116 enum class TxnState : U8 {
117 TXN_STATE_UNDEF = 0, /**< \brief State assigned to an unused object on the free list */
118 TXN_STATE_INIT = 1, /**< \brief State assigned to a newly allocated transaction object */
119 TXN_STATE_R1 = 2, /**< \brief Receive file as class 1 */
120 TXN_STATE_S1 = 3, /**< \brief Send file as class 1 */
121 TXN_STATE_R2 = 4, /**< \brief Receive file as class 2 */
122 TXN_STATE_S2 = 5, /**< \brief Send file as class 2 */
123 TXN_STATE_DROP = 6, /**< \brief State where all PDUs are dropped */
124 TXN_STATE_HOLD = 7, /**< \brief State assigned to a transaction after freeing it */
125 TXN_STATE_INVALID = 8 /**< \brief Marker value for the highest possible state number */
126 };
127
128 /**
129 * @brief Sub-state of a send file transaction
130 */
131 enum class TxSubState : U8 {
132 TX_SUB_STATE_METADATA = 0, /**< sending the initial MD directive */
133 TX_SUB_STATE_FILEDATA = 1, /**< sending file data PDUs */
134 TX_SUB_STATE_EOF = 2, /**< sending the EOF directive */
135 TX_SUB_STATE_CLOSEOUT_SYNC = 3, /**< pending final acks from remote */
136 TX_SUB_STATE_NUM_STATES = 4
137 };
138
139 /**
140 * @brief Sub-state of a receive file transaction
141 */
142 enum class RxSubState : U8 {
143 RX_SUB_STATE_FILEDATA = 0, /**< receive file data PDUs */
144 RX_SUB_STATE_EOF = 1, /**< got EOF directive */
145 RX_SUB_STATE_CLOSEOUT_SYNC = 2, /**< pending final acks from remote */
146 RX_SUB_STATE_NUM_STATES = 3
147 };
148
149 /**
150 * @brief Direction identifier
151 *
152 * Differentiates between send and receive history entries
153 */
154 enum class Direction : U8 {
155 DIRECTION_RX = 0,
156 DIRECTION_TX = 1,
157 DIRECTION_NUM = 2,
158 };
159
160 /**
161 * @brief Transaction initiation method
162 *
163 * Differentiates between command-initiated and port-initiated transactions
164 */
165 enum class TransactionInitType : U8 {
166 INIT_BY_COMMAND = 0, //!< Transaction initiated via command interface
167 INIT_BY_PORT = 1 //!< Transaction initiated via port interface
168 };
169
170 /**
171 * @brief Identifies the type of timer tick being processed
172 */
173 enum class CfdpTickType : U8 {
174 CFDP_TICK_TYPE_RX,
175 CFDP_TICK_TYPE_TXW_NORM,
176 CFDP_TICK_TYPE_TXW_NAK,
177 CFDP_TICK_TYPE_NUM_TYPES
178 };
179
180 /**
181 * @brief Values for Transaction Status code
182 *
183 * This enum defines the possible values representing the
184 * result of a transaction. This is a superset of the condition codes
185 * defined in CCSDS book 727 (condition codes) but with additional
186 * values for local conditions that the blue book does not have,
187 * such as protocol/state machine or decoding errors.
188 *
189 * The values here are designed to not overlap with the condition
190 * codes defined in the blue book, but can be translated to one
191 * of those codes for the purposes of FIN/ACK/EOF PDUs.
192 */
193 enum class TxnStatus : I32 {
194 /**
195 * The undefined status is a placeholder for new transactions before a value is set.
196 */
197 TXN_STATUS_UNDEFINED = -1,
198
199 /* Status codes 0-15 share the same values/meanings as the CFDP condition code (CC) */
200 TXN_STATUS_NO_ERROR = static_cast<I32>(ConditionCode::CONDITION_CODE_NO_ERROR),
201 TXN_STATUS_POS_ACK_LIMIT_REACHED = static_cast<I32>(ConditionCode::CONDITION_CODE_POS_ACK_LIMIT_REACHED),
202 TXN_STATUS_KEEP_ALIVE_LIMIT_REACHED = static_cast<I32>(ConditionCode::CONDITION_CODE_KEEP_ALIVE_LIMIT_REACHED),
203 TXN_STATUS_INVALID_TRANSMISSION_MODE = static_cast<I32>(ConditionCode::CONDITION_CODE_INVALID_TRANSMISSION_MODE),
204 TXN_STATUS_FILESTORE_REJECTION = static_cast<I32>(ConditionCode::CONDITION_CODE_FILESTORE_REJECTION),
205 TXN_STATUS_FILE_CHECKSUM_FAILURE = static_cast<I32>(ConditionCode::CONDITION_CODE_FILE_CHECKSUM_FAILURE),
206 TXN_STATUS_FILE_SIZE_ERROR = static_cast<I32>(ConditionCode::CONDITION_CODE_FILE_SIZE_ERROR),
207 TXN_STATUS_NAK_LIMIT_REACHED = static_cast<I32>(ConditionCode::CONDITION_CODE_NAK_LIMIT_REACHED),
208 TXN_STATUS_INACTIVITY_DETECTED = static_cast<I32>(ConditionCode::CONDITION_CODE_INACTIVITY_DETECTED),
209 TXN_STATUS_INVALID_FILE_STRUCTURE = static_cast<I32>(ConditionCode::CONDITION_CODE_INVALID_FILE_STRUCTURE),
210 TXN_STATUS_CHECK_LIMIT_REACHED = static_cast<I32>(ConditionCode::CONDITION_CODE_CHECK_LIMIT_REACHED),
211 TXN_STATUS_UNSUPPORTED_CHECKSUM_TYPE = static_cast<I32>(ConditionCode::CONDITION_CODE_UNSUPPORTED_CHECKSUM_TYPE),
212 TXN_STATUS_SUSPEND_REQUEST_RECEIVED = static_cast<I32>(ConditionCode::CONDITION_CODE_SUSPEND_REQUEST_RECEIVED),
213 TXN_STATUS_CANCEL_REQUEST_RECEIVED = static_cast<I32>(ConditionCode::CONDITION_CODE_CANCEL_REQUEST_RECEIVED),
214
215 /* Additional status codes for items not representable in a CFDP CC, these can be set in
216 * transactions that did not make it to the point of sending FIN/EOF. */
217 TXN_STATUS_PROTOCOL_ERROR = 16,
218 TXN_STATUS_ACK_LIMIT_NO_FIN = 17,
219 TXN_STATUS_ACK_LIMIT_NO_EOF = 18,
220 TXN_STATUS_NAK_RESPONSE_ERROR = 19,
221 TXN_STATUS_SEND_EOF_FAILURE = 20,
222 TXN_STATUS_EARLY_FIN = 21,
223
224 /* keep last */
225 TXN_STATUS_MAX = 22
226 };
227
228 /**
229 * @brief Cache of source and destination filename
230 *
231 * This pairs a source and destination file name together
232 * to be retained for future reference in the transaction/history
233 */
234 struct CfdpTxnFilenames {
235 Fw::String src_filename;
236 Fw::String dst_filename;
237 };
238
239 /**
240 * @brief CFDP History entry
241 *
242 * Records CFDP operations for future reference
243 */
244 struct History {
245 CfdpTxnFilenames fnames; /**< \brief file names associated with this history entry */
246 CListNode cl_node; /**< \brief for connection to a CList */
247 Direction dir; /**< \brief direction of this history entry */
248 TxnStatus txn_stat; /**< \brief final status of operation */
249 EntityId src_eid; /**< \brief the source eid of the transaction */
250 EntityId peer_eid; /**< \brief peer_eid is always the "other guy", same src_eid for RX */
251 TransactionSeq seq_num; /**< \brief transaction identifier, stays constant for entire transfer */
252 };
253
254 /**
255 * @brief Wrapper around a CfdpChunkList object
256 *
257 * This allows a CfdpChunkList to be stored within a CList data storage structure.
258 * The wrapper is pooled by Channel for reuse across transactions.
259 */
260 struct CfdpChunkWrapper {
261 CfdpChunkList chunks; //!< Chunk list for gap tracking
262 CListNode cl_node; //!< Circular list node for pooling
263
264 /**
265 * @brief Constructor for initializing the chunk list
266 *
267 * @param maxChunks Maximum number of chunks this list can hold
268 * @param chunkMem Pointer to pre-allocated chunk memory
269 */
270 CfdpChunkWrapper(ChunkIdx maxChunks, Chunk* chunkMem) : chunks(maxChunks, chunkMem), cl_node{} {}
271 };
272
273 /**
274 * @brief CFDP Playback entry
275 *
276 * Keeps the state of CFDP playback requests
277 */
278 struct Playback {
279 Os::Directory dir;
280 Class::T cfdp_class;
281 CfdpTxnFilenames fnames;
282 U16 num_ts; /**< \brief number of transactions */
283 U8 priority;
284 EntityId dest_id;
285 Fw::StringTemplate<MaxFilePathSize> pending_file;
286
287 bool busy;
288 bool diropen;
289 Keep::T keep;
290 bool counted;
291 };
292
293 /**
294 * \brief Directory poll entry
295 *
296 * Keeps the state of CFDP directory polling
297 */
298 struct CfdpPollDir {
299 Playback pb; /**< \brief State of the current playback requests */
300 Timer intervalTimer; /**< \brief Timer object used to poll the directory */
301
302 U32 intervalSec; /**< \brief number of seconds to wait before trying a new directory */
303
304 U8 priority; /**< \brief priority to use when placing transactions on the pending queue */
305 Class::T cfdpClass; /**< \brief the CFDP class to send */
306 EntityId destEid; /**< \brief destination entity id */
307
308 Fw::String srcDir; /**< \brief path to source dir */
309 Fw::String dstDir; /**< \brief path to destination dir */
310
311 Fw::Enabled enabled; /**< \brief Enabled flag */
312 };
313
314 /**
315 * @brief Data specific to a class 2 send file transaction
316 */
317 struct CfdpTxS2Data {
318 U8 fin_cc; /**< \brief remember the cc in the received FIN PDU to echo in eof-fin */
319 U8 acknak_count;
320 };
321
322 /**
323 * @brief Data specific to a send file transaction
324 */
325 struct CfdpTxStateData {
326 TxSubState sub_state;
327 FileSize cached_pos;
328
329 CfdpTxS2Data s2;
330 };
331
332 /**
333 * @brief Data specific to a class 2 receive file transaction
334 */
335 struct CfdpRxS2Data {
336 U32 eof_crc;
337 FileSize eof_size;
338 FileSize rx_crc_calc_bytes;
339 FinDeliveryCode dc;
340 FinFileStatus fs;
341 U8 eof_cc; /**< \brief remember the cc in the received EOF PDU to echo in eof-ack */
342 U8 acknak_count;
343 };
344
345 /**
346 * @brief Data specific to a receive file transaction
347 */
348 struct CfdpRxStateData {
349 RxSubState sub_state;
350 FileSize cached_pos;
351
352 CfdpRxS2Data r2;
353 };
354
355 /**
356 * @brief Data that applies to all types of transactions
357 */
358 struct CfdpFlagsCommon {
359 U8 q_index; /**< \brief Q index this is in */
360 bool ack_timer_armed;
361 bool suspended;
362 bool canceled;
363 bool crc_calc;
364 bool inactivity_fired; /**< \brief set whenever the inactivity timeout expires */
365 bool keep_history; /**< \brief whether history should be preserved during recycle */
366 U8 post_inactivity_send_retries; /**< \brief terminal-send retries attempted after inactivity fired */
367 };
368
369 /**
370 * @brief Flags that apply to receive transactions
371 */
372 struct CfdpFlagsRx {
373 CfdpFlagsCommon com;
374
375 bool md_recv; /**< \brief md received for r state */
376 bool eof_recv;
377 bool send_nak;
378 bool send_fin;
379 bool send_eof_ack;
380 bool complete; /**< \brief r2 */
381 bool fd_nak_sent; /**< \brief latches that at least one NAK has been sent for file data */
382 };
383
384 /**
385 * @brief Flags that apply to send transactions
386 */
387 struct CfdpFlagsTx {
388 CfdpFlagsCommon com;
389
390 bool md_need_send;
391 bool send_eof;
392 bool eof_ack_recv;
393 bool fin_recv;
394 bool send_fin_ack;
395 bool cmd_tx; /**< \brief indicates transaction is commanded (ground) tx */
396 };
397
398 /**
399 * @brief Summary of all possible transaction flags (tx and rx)
400 */
401 union CfdpStateFlags {
402 CfdpFlagsCommon com; /**< \brief applies to all transactions */
403 CfdpFlagsRx rx; /**< \brief applies to only receive file transactions */
404 CfdpFlagsTx tx; /**< \brief applies to only send file transactions */
405 };
406
407 /**
408 * @brief Summary of all possible transaction state information (tx and rx)
409 */
410 union CfdpStateData {
411 CfdpTxStateData send; /**< \brief applies to only send file transactions */
412 CfdpRxStateData receive; /**< \brief applies to only receive file transactions */
413 };
414
415 /**
416 * @brief Callback function type for use with Channel::traverseAllTransactions()
417 *
418 * @param txn Pointer to current transaction being traversed
419 * @param context Opaque object passed from initial call
420 */
421 using CfdpTraverseAllTransactionsFunc = void (*)(Transaction* txn, void* context);
422
423 } // namespace Cfdp
424 } // namespace Ccsds
425 } // namespace Svc
426
427 #endif // Svc_Ccsds_Cfdp_Types_HPP
428