-
Notifications
You must be signed in to change notification settings - Fork 47
/
cf_cmd.c
1209 lines (1106 loc) · 40.1 KB
/
cf_cmd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/************************************************************************
* NASA Docket No. GSC-18,447-1, and identified as “CFS CFDP (CF)
* Application version 3.0.0”
*
* Copyright (c) 2019 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
/**
* @file
*
* The CF Application command handling source file
*
* All ground commands are processed in this file. All supporting functions
* necessary to process the commands are also here.
*/
#include "cf_app.h"
#include "cf_verify.h"
#include "cf_events.h"
#include "cf_perfids.h"
#include "cf_utils.h"
#include "cf_version.h"
#include "cf_cfdp.h"
#include "cf_cmd.h"
#include <string.h>
#define ALL_CHANNELS (255)
#define ALL_POLLDIRS (ALL_CHANNELS)
#define COMPOUND_KEY (254)
/*----------------------------------------------------------------
*
* Function: CF_CmdNoop
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdNoop(CFE_SB_Buffer_t *msg)
{
CFE_EVS_SendEvent(CF_EID_INF_CMD_NOOP, CFE_EVS_EventType_INFORMATION, "CF: No-Op received, Version %d.%d.%d.%d",
CF_MAJOR_VERSION, CF_MINOR_VERSION, CF_REVISION, CF_MISSION_REV);
CF_CmdAcc();
}
/*----------------------------------------------------------------
*
* Function: CF_CmdReset
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdReset(CFE_SB_Buffer_t *msg)
{
static const int counters_command = 1;
static const int counters_fault = 2;
static const int counters_up = 3;
static const int counters_down = 4;
CF_UnionArgsCmd_t *cmd = (CF_UnionArgsCmd_t *)msg;
static const char *names[5] = {"all", "cmd", "fault", "up", "down"};
/* 0=all, 1=cmd, 2=fault 3=up 4=down */
uint8 param = cmd->data.byte[0];
int i;
int acc = 1;
if (param > 4)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_RESET_INVALID, CFE_EVS_EventType_ERROR,
"CF: Received RESET COUNTERS command with invalid parameter %d", param);
CF_CmdRej();
goto err_out;
}
CFE_EVS_SendEvent(CF_EID_INF_CMD_RESET, CFE_EVS_EventType_INFORMATION, "CF: Received RESET COUNTERS command: %s",
names[param]);
/* if the param is counters_command, or all counters */
if (!param || (param == counters_command))
{
/* command counters */
memset(&CF_AppData.hk.counters, 0, sizeof(CF_AppData.hk.counters));
acc = 0; /* don't increment accept counter on command counter reset */
}
/* if the param is counters_fault, or all counters */
if (!param || (param == counters_fault))
{
/* fault counters */
for (i = 0; i < CF_NUM_CHANNELS; ++i)
memset(&CF_AppData.hk.channel_hk[i].counters.fault, 0, sizeof(CF_AppData.hk.channel_hk[i].counters.fault));
}
/* if the param is counters_up, or all counters */
if (!param || (param == counters_up))
{
/* up counters */
for (i = 0; i < CF_NUM_CHANNELS; ++i)
memset(&CF_AppData.hk.channel_hk[i].counters.recv, 0, sizeof(CF_AppData.hk.channel_hk[i].counters.recv));
}
/* if the param is counters_down, or all counters */
if (!param || (param == counters_down))
{
/* down counters */
for (i = 0; i < CF_NUM_CHANNELS; ++i)
memset(&CF_AppData.hk.channel_hk[i].counters.sent, 0, sizeof(CF_AppData.hk.channel_hk[i].counters.sent));
}
if (acc)
{
CF_CmdAcc();
}
err_out:;
}
/*----------------------------------------------------------------
*
* Function: CF_CmdTxFile
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdTxFile(CFE_SB_Buffer_t *msg)
{
CF_TxFileCmd_t *tx = (CF_TxFileCmd_t *)msg;
/*
* This needs to validate all its inputs.
* "keep" should only be 0 or 1 (logical true/false).
* For priority and dest_id params, anything is acceptable.
*/
if (tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS || tx->keep > 1)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_BAD_PARAM, CFE_EVS_EventType_ERROR,
"CF: bad parameter in CF_CmdTxFile(): chan=%u, class=%u keep=%u", (unsigned int)tx->chan_num,
(unsigned int)tx->cfdp_class, (unsigned int)tx->keep);
CF_CmdRej();
return;
}
/* make sure that the src and dst filenames are null terminated */
tx->src_filename[sizeof(tx->src_filename) - 1] = 0;
tx->dst_filename[sizeof(tx->dst_filename) - 1] = 0;
CF_CmdCond(CF_CFDP_TxFile(tx->src_filename, tx->dst_filename, tx->cfdp_class, tx->keep, tx->chan_num, tx->priority,
tx->dest_id));
}
/*----------------------------------------------------------------
*
* Function: CF_CmdPlaybackDir
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdPlaybackDir(CFE_SB_Buffer_t *msg)
{
CF_PlaybackDirCmd_t *tx = (CF_PlaybackDirCmd_t *)msg;
/*
* This needs to validate all its inputs.
* "keep" should only be 0 or 1 (logical true/false).
* For priority and dest_id params, anything is acceptable.
*/
if (tx->cfdp_class > CF_CFDP_CLASS_2 || tx->chan_num >= CF_NUM_CHANNELS || tx->keep > 1)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_BAD_PARAM, CFE_EVS_EventType_ERROR,
"CF: bad parameter in CF_CmdPlaybackDir(): chan=%u, class=%u keep=%u",
(unsigned int)tx->chan_num, (unsigned int)tx->cfdp_class, (unsigned int)tx->keep);
CF_CmdRej();
return;
}
/* make sure that the src and dst filenames are null terminated */
tx->src_filename[sizeof(tx->src_filename) - 1] = 0;
tx->dst_filename[sizeof(tx->dst_filename) - 1] = 0;
CF_CmdCond(CF_CFDP_PlaybackDir(tx->src_filename, tx->dst_filename, tx->cfdp_class, tx->keep, tx->chan_num,
tx->priority, tx->dest_id));
}
/*----------------------------------------------------------------
*
* Function: CF_DoChanAction
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_DoChanAction(CF_UnionArgsCmd_t *cmd, const char *errstr, CF_ChanActionFn_t fn, void *context)
{
int ret = 0;
/* this function is generic for any ground command that takes a single channel
* argument which must be less than CF_NUM_CHANNELS or 255 which is a special
* value that means apply command to all channels */
if (cmd->data.byte[0] == ALL_CHANNELS)
{
/* apply to all channels */
int i;
for (i = 0; i < CF_NUM_CHANNELS; ++i)
ret |= fn(i, context);
}
else if (cmd->data.byte[0] < CF_NUM_CHANNELS)
{
ret = fn(cmd->data.byte[0], context);
}
else
{
/* bad parameter */
CFE_EVS_SendEvent(CF_EID_ERR_CMD_CHAN_PARAM, CFE_EVS_EventType_ERROR,
"CF: %s: channel parameter out of range. received %d", errstr, cmd->data.byte[0]);
ret = -1;
}
return ret;
}
/*----------------------------------------------------------------
*
* Function: CF_DoFreezeThaw
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_DoFreezeThaw(uint8 chan_num, const CF_ChanAction_BoolArg_t *context)
{
/* no need to bounds check chan_num, done in caller */
CF_AppData.hk.channel_hk[chan_num].frozen = context->barg;
return 0;
}
/*----------------------------------------------------------------
*
* Function: CF_CmdFreeze
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdFreeze(CFE_SB_Buffer_t *msg)
{
CF_ChanAction_BoolArg_t barg = {1}; /* param is frozen, so 1 means freeze */
CF_CmdCond(CF_DoChanAction((CF_UnionArgsCmd_t *)msg, "freeze", (CF_ChanActionFn_t)CF_DoFreezeThaw, &barg));
}
/*----------------------------------------------------------------
*
* Function: CF_CmdThaw
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdThaw(CFE_SB_Buffer_t *msg)
{
CF_ChanAction_BoolArg_t barg = {0}; /* param is frozen, so 0 means thawed */
CF_CmdCond(CF_DoChanAction((CF_UnionArgsCmd_t *)msg, "thaw", (CF_ChanActionFn_t)CF_DoFreezeThaw, &barg));
}
/*----------------------------------------------------------------
*
* Function: CF_FindTransactionBySequenceNumberAllChannels
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
CF_Transaction_t *CF_FindTransactionBySequenceNumberAllChannels(CF_TransactionSeq_t ts, CF_EntityId_t eid)
{
int i;
CF_Transaction_t *ret = NULL;
/* transaction sequence numbers are referenced with the tuple (eid, tsn)
* Even though these tuples are unique to a channel, they should be unique
* across the entire system. Meaning, it isn't correect to have the same
* EID re-using a TSN in the same system. So, in order to locate the transaction
* to suspend, we need to search across all channels for it. */
for (i = 0; i < CF_NUM_CHANNELS; ++i)
{
ret = CF_FindTransactionBySequenceNumber(CF_AppData.engine.channels + i, ts, eid);
if (ret)
{
break;
}
}
return ret;
}
/*----------------------------------------------------------------
*
* Function: CF_TsnChanAction
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_TsnChanAction(CF_TransactionCmd_t *cmd, const char *cmdstr, CF_TsnChanAction_fn_t fn, void *context)
{
int ret = -1;
if (cmd->chan == COMPOUND_KEY)
{
/* special value 254 means to use the compound key (cmd->eid, cmd->ts) to find the transaction
* to act upon */
CF_Transaction_t *t = CF_FindTransactionBySequenceNumberAllChannels(cmd->ts, cmd->eid);
if (t)
{
fn(t, context);
ret = 1; /* because one transaction was matched - this should return a count */
}
else
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_TRANS_NOT_FOUND, CFE_EVS_EventType_ERROR,
"CF: %s cmd: failed to find transactino for (eid %lu, ts %lu)", cmdstr,
(unsigned long)cmd->eid, (unsigned long)cmd->ts);
}
}
else if (cmd->chan == ALL_CHANNELS)
{
/* perform action on all channels, all transactions */
ret = CF_TraverseAllTransactions_All_Channels(fn, context);
}
else if (cmd->chan < CF_NUM_CHANNELS)
{
/* perform action on a specific channel, all transactions */
ret = CF_TraverseAllTransactions(CF_AppData.engine.channels + cmd->chan, fn, context);
}
else
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_TSN_CHAN_INVALID, CFE_EVS_EventType_ERROR, "CF: %s cmd: invalid channel %d",
cmdstr, cmd->chan);
}
return ret;
}
/*----------------------------------------------------------------
*
* Function: CF_DoSuspRes_Txn
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_DoSuspRes_Txn(CF_Transaction_t *t, CF_ChanAction_SuspResArg_t *context)
{
CF_Assert(t);
if (t->flags.com.suspended == context->action)
{
context->same = 1;
}
else
{
t->flags.com.suspended = context->action;
}
}
/*----------------------------------------------------------------
*
* Function: CF_DoSuspRes
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_DoSuspRes(CF_TransactionCmd_t *cmd, uint8 action)
{
/* ok to not bounds check action, because the caller is using it in two places with constant values 0 or 1 */
static const char * msgstr[] = {"resume", "suspend"};
CF_ChanAction_SuspResArg_t args = {0, action};
int ret = CF_TsnChanAction(cmd, msgstr[action], (CF_TsnChanAction_fn_t)CF_DoSuspRes_Txn, &args);
/*
* Note that this command may affect multiple transactions, depending on the value of the "chan" argument.
* When acting on multiple channels, the "same" output does not apply. In reality all it means is
* that one of the affected channels was already set that way.
*/
if (ret == 1 && args.same)
{
/* A single transaction was mached, and it was already set the same way */
CFE_EVS_SendEvent(CF_EID_ERR_CMD_SUSPRES_SAME, CFE_EVS_EventType_ERROR,
"CF: %s cmd: setting suspend flag to current value of %d", msgstr[action], action);
CF_CmdRej();
}
else if (ret <= 0)
{
/* No transaction was matched for the given combination of chan + eid + ts */
CFE_EVS_SendEvent(CF_EID_ERR_CMD_SUSPRES_CHAN, CFE_EVS_EventType_ERROR, "CF: %s cmd: no transaction found",
msgstr[action]);
CF_CmdRej();
}
else
{
CF_CmdAcc();
}
}
/*----------------------------------------------------------------
*
* Function: CF_CmdSuspend
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdSuspend(CFE_SB_Buffer_t *msg)
{
CF_DoSuspRes((CF_TransactionCmd_t *)msg, 1);
}
/*----------------------------------------------------------------
*
* Function: CF_CmdResume
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdResume(CFE_SB_Buffer_t *msg)
{
CF_DoSuspRes((CF_TransactionCmd_t *)msg, 0);
}
/*----------------------------------------------------------------
*
* Function: CF_CmdCancel_Txn
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdCancel_Txn(CF_Transaction_t *t, void *ignored)
{
CF_CFDP_CancelTransaction(t);
}
/*----------------------------------------------------------------
*
* Function: CF_CmdCancel
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdCancel(CFE_SB_Buffer_t *msg)
{
/* note that CF_TsnChanAction() returns the number of transactions affected, so <= 0 means failure.
* CF_CmdCond() accepts 0 (logical false) to mean success, nonzero (logical true) to mean failure */
CF_CmdCond(CF_TsnChanAction((CF_TransactionCmd_t *)msg, "cancel", CF_CmdCancel_Txn, NULL) <= 0);
}
/*----------------------------------------------------------------
*
* Function: CF_CmdAbandon_Txn
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdAbandon_Txn(CF_Transaction_t *t, void *ignored)
{
CF_CFDP_ResetTransaction(t, 0);
}
/*----------------------------------------------------------------
*
* Function: CF_CmdAbandon
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdAbandon(CFE_SB_Buffer_t *msg)
{
/* note that CF_TsnChanAction() returns the number of transactions affected, so <= 0 means failure.
* CF_CmdCond() accepts 0 (logical false) to mean success, nonzero (logical true) to mean failure */
CF_CmdCond(CF_TsnChanAction((CF_TransactionCmd_t *)msg, "abandon", CF_CmdAbandon_Txn, NULL) <= 0);
}
/*----------------------------------------------------------------
*
* Function: CF_DoEnableDisableDequeue
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_DoEnableDisableDequeue(uint8 chan_num, const CF_ChanAction_BoolArg_t *context)
{
/* no need to bounds check chan_num, done in caller */
CF_AppData.config_table->chan[chan_num].dequeue_enabled = context->barg;
return 0;
}
/*----------------------------------------------------------------
*
* Function: CF_CmdEnableDequeue
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdEnableDequeue(CFE_SB_Buffer_t *msg)
{
CF_ChanAction_BoolArg_t barg = {1};
CF_CmdCond(CF_DoChanAction((CF_UnionArgsCmd_t *)msg, "enable_dequeue", (CF_ChanActionFn_t)CF_DoEnableDisableDequeue,
&barg));
}
/*----------------------------------------------------------------
*
* Function: CF_CmdDisableDequeue
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdDisableDequeue(CFE_SB_Buffer_t *msg)
{
CF_ChanAction_BoolArg_t barg = {0};
CF_CmdCond(CF_DoChanAction((CF_UnionArgsCmd_t *)msg, "disable_dequeue",
(CF_ChanActionFn_t)CF_DoEnableDisableDequeue, &barg));
}
/*----------------------------------------------------------------
*
* Function: CF_DoEnableDisablePolldir
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_DoEnableDisablePolldir(uint8 chan_num, const CF_ChanAction_BoolMsgArg_t *context)
{
int ret = 0;
/* no need to bounds check chan_num, done in caller */
if (context->msg->data.byte[1] == ALL_POLLDIRS)
{
/* all polldirs in channel */
int i;
for (i = 0; i < CF_MAX_POLLING_DIR_PER_CHAN; ++i)
CF_AppData.config_table->chan[chan_num].polldir[i].enabled = context->barg;
}
else if (context->msg->data.byte[1] < CF_MAX_POLLING_DIR_PER_CHAN)
{
CF_AppData.config_table->chan[chan_num].polldir[context->msg->data.byte[1]].enabled = context->barg;
}
else
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_POLLDIR_INVALID, CFE_EVS_EventType_ERROR,
"CF: enable/disable polldir: invalid polldir %d on channel %d", context->msg->data.byte[1],
chan_num);
ret = -1;
}
return ret;
}
/*----------------------------------------------------------------
*
* Function: CF_CmdEnablePolldir
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdEnablePolldir(CFE_SB_Buffer_t *msg)
{
CF_ChanAction_BoolMsgArg_t barg = {(CF_UnionArgsCmd_t *)msg, 1};
CF_CmdCond(CF_DoChanAction((CF_UnionArgsCmd_t *)msg, "enable_polldir", (CF_ChanActionFn_t)CF_DoEnableDisablePolldir,
&barg));
}
/*----------------------------------------------------------------
*
* Function: CF_CmdDisablePolldir
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdDisablePolldir(CFE_SB_Buffer_t *msg)
{
CF_ChanAction_BoolMsgArg_t barg = {(CF_UnionArgsCmd_t *)msg, 0};
CF_CmdCond(CF_DoChanAction((CF_UnionArgsCmd_t *)msg, "disable_polldir",
(CF_ChanActionFn_t)CF_DoEnableDisablePolldir, &barg));
}
/*----------------------------------------------------------------
*
* Function: CF_PurgeHistory
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_PurgeHistory(CF_CListNode_t *n, CF_Channel_t *c)
{
CF_History_t *h = container_of(n, CF_History_t, cl_node);
CF_ResetHistory(c, h); /* ok to reset transaction since it's in PEND it hasn't started yet */
return CF_CLIST_CONT;
}
/*----------------------------------------------------------------
*
* Function: CF_PurgeTransaction
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_PurgeTransaction(CF_CListNode_t *n, void *ignored)
{
CF_Transaction_t *t = container_of(n, CF_Transaction_t, cl_node);
CF_CFDP_ResetTransaction(t, 0);
return CF_CLIST_CONT;
}
/*----------------------------------------------------------------
*
* Function: CF_DoPurgeQueue
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_DoPurgeQueue(uint8 chan_num, CF_UnionArgsCmd_t *cmd)
{
int ret = 0;
/* no need to bounds check chan_num, done in caller */
CF_Channel_t *c = &CF_AppData.engine.channels[chan_num];
int pend = 0;
int hist = 0;
switch (cmd->data.byte[1])
{
case 0: /* pend */
pend = 1;
break;
case 1: /* history */
hist = 1;
break;
case 2: /* both */
pend = 1;
hist = 1;
break;
default:
CFE_EVS_SendEvent(CF_EID_ERR_CMD_PURGE_ARG, CFE_EVS_EventType_ERROR, "CF: purge queue invalid arg %d",
cmd->data.byte[1]);
ret = -1;
break;
}
if (pend)
{
CF_CList_Traverse(c->qs[CF_QueueIdx_PEND], CF_PurgeTransaction, NULL);
}
if (hist)
{
CF_CList_Traverse(c->qs[CF_QueueIdx_HIST], (CF_CListFn_t)CF_PurgeHistory, c);
}
return ret;
}
/*----------------------------------------------------------------
*
* Function: CF_CmdPurgeQueue
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdPurgeQueue(CFE_SB_Buffer_t *msg)
{
CF_CmdCond(CF_DoChanAction((CF_UnionArgsCmd_t *)msg, "purge_queue", (CF_ChanActionFn_t)CF_DoPurgeQueue, msg));
}
/*----------------------------------------------------------------
*
* Function: CF_CmdWriteQueue
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdWriteQueue(CFE_SB_Buffer_t *msg)
{
/* a type value of 0 means to process both type_up and type_down */
static const int type_up = 1;
static const int type_down = 2;
static const int q_pend = 0;
static const int q_active = 1;
static const int q_history = 2;
static const int q_all = 3;
CF_WriteQueueCmd_t *wq = (CF_WriteQueueCmd_t *)msg;
CF_Channel_t * c = &CF_AppData.engine.channels[wq->chan];
osal_id_t fd = OS_OBJECT_ID_UNDEFINED;
int32 ret;
/* check the commands for validity */
if (wq->chan >= CF_NUM_CHANNELS)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_CHAN, CFE_EVS_EventType_ERROR, "CF: write queue invalid channel arg");
goto bail;
}
/* only invalid combination is up direction, pending queue */
if ((wq->type == type_up) && (wq->queue == q_pend))
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_ARGS, CFE_EVS_EventType_ERROR,
"CF: write queue invalid command parameters");
goto bail;
}
/* PTFO: queues can be large. may want to split this work up across the state machine and take several wakeups to
* complete */
ret = CF_WrappedOpenCreate(&fd, wq->filename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
if (ret < 0)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_OPEN, CFE_EVS_EventType_ERROR, "CF: write queue failed to open file %s",
wq->filename);
goto bail;
}
/* if type is type_up, or all types */
if (!wq->type || (wq->type == type_up))
{
/* process uplink queue data */
if ((wq->queue == q_all) || (wq->queue == q_active))
{
ret = CF_WriteTxnQueueDataToFile(fd, c, CF_QueueIdx_RX);
if (ret)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_WRITEQ_RX, CFE_EVS_EventType_ERROR,
"CF: write queue failed to write CF_QueueIdx_RX data");
goto out_close;
}
}
if ((wq->queue == q_all) || (wq->queue == q_history))
{
ret = CF_WriteHistoryQueueDataToFile(fd, c, CF_Direction_RX);
if (ret)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_WRITEHIST_RX, CFE_EVS_EventType_ERROR,
"CF: write queue failed to write history RX data");
goto out_close;
}
}
}
/* if type is type_down, or all types */
if (!wq->type || (wq->type == type_down))
{
/* process downlink queue data */
if ((wq->queue == q_all) || (wq->queue == q_active))
{
int i;
static const int qs[2] = {CF_QueueIdx_TXA, CF_QueueIdx_TXW};
for (i = 0; i < 2; ++i)
{
ret = CF_WriteTxnQueueDataToFile(fd, c, qs[i]);
if (ret)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_WRITEQ_TX, CFE_EVS_EventType_ERROR,
"CF: write queue failed to write q index %d", qs[i]);
goto out_close;
}
}
}
if ((wq->queue == q_all) || (wq->queue == q_pend))
{
/* write pending queue */
ret = CF_WriteTxnQueueDataToFile(fd, c, CF_QueueIdx_PEND);
if (ret)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_WRITEQ_PEND, CFE_EVS_EventType_ERROR,
"CF: write queue failed to write pending queue");
goto out_close;
}
}
if ((wq->queue == q_all) || (wq->queue == q_history))
{
/* write history queue */
ret = CF_WriteHistoryQueueDataToFile(fd, c, CF_Direction_TX);
if (ret)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_WQ_WRITEHIST_TX, CFE_EVS_EventType_ERROR,
"CF: write queue failed to write CF_QueueIdx_TX data");
goto out_close;
}
}
}
CF_CmdAcc();
return;
out_close:
CF_WrappedClose(fd);
bail:
CF_CmdRej();
}
/*----------------------------------------------------------------
*
* Function: CF_CmdValidateChunkSize
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_CmdValidateChunkSize(uint32 val, uint8 chan_num /* ignored */)
{
int ret = 0;
if (val > sizeof(CF_CFDP_PduFileDataContent_t))
{
ret = 1; /* failed */
}
return ret;
}
/*----------------------------------------------------------------
*
* Function: CF_CmdValidateMaxOutgoing
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
int CF_CmdValidateMaxOutgoing(uint32 val, uint8 chan_num)
{
int ret = 0;
if (!val && !CF_AppData.config_table->chan[chan_num].sem_name[0])
{
/* can't have unlimited messages and no semaphore */
ret = 1; /* failed */
}
return ret;
}
/*----------------------------------------------------------------
*
* Function: CF_CmdGetSetParam
*
* Application-scope internal function
* See description in cf_cmd.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_CmdGetSetParam(uint8 is_set, CF_GetSet_ValueID_t param_id, uint32 value, uint8 chan_num)
{
CF_ConfigTable_t *config;
int acc;
bool valid_set;
struct
{
void * ptr;
uint32 size;
int (*fn)(uint32, uint8 chan_num);
} item;
acc = 1; /* 1 means to reject */
valid_set = false;
config = CF_AppData.config_table;
memset(&item, 0, sizeof(item));
switch (param_id)
{
case CF_GetSet_ValueID_ticks_per_second:
item.ptr = &config->ticks_per_second;
item.size = sizeof(config->ticks_per_second);
break;
case CF_GetSet_ValueID_rx_crc_calc_bytes_per_wakeup:
item.ptr = &config->rx_crc_calc_bytes_per_wakeup;
item.size = sizeof(config->rx_crc_calc_bytes_per_wakeup);
break;
case CF_GetSet_ValueID_ack_timer_s:
item.ptr = &config->chan[chan_num].ack_timer_s;
item.size = sizeof(config->chan[chan_num].ack_timer_s);
break;
case CF_GetSet_ValueID_nak_timer_s:
item.ptr = &config->chan[chan_num].nak_timer_s;
item.size = sizeof(config->chan[chan_num].nak_timer_s);
break;
case CF_GetSet_ValueID_inactivity_timer_s:
item.ptr = &config->chan[chan_num].inactivity_timer_s;
item.size = sizeof(config->chan[chan_num].inactivity_timer_s);
break;
case CF_GetSet_ValueID_outgoing_file_chunk_size:
item.ptr = &config->outgoing_file_chunk_size;
item.size = sizeof(config->outgoing_file_chunk_size);
item.fn = CF_CmdValidateChunkSize;
break;
case CF_GetSet_ValueID_ack_limit:
item.ptr = &config->chan[chan_num].ack_limit;
item.size = sizeof(config->chan[chan_num].ack_limit);
break;
case CF_GetSet_ValueID_nak_limit:
item.ptr = &config->chan[chan_num].nak_limit;
item.size = sizeof(config->chan[chan_num].nak_limit);
break;
case CF_GetSet_ValueID_local_eid:
item.ptr = &config->local_eid;
item.size = sizeof(config->local_eid);
break;
case CF_GetSet_ValueID_chan_max_outgoing_messages_per_wakeup:
item.ptr = &config->chan[chan_num].max_outgoing_messages_per_wakeup;
item.size = sizeof(config->chan[chan_num].max_outgoing_messages_per_wakeup);
item.fn = CF_CmdValidateMaxOutgoing;
break;
default:
break;
};
if (item.size == 0)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_GETSET_PARAM, CFE_EVS_EventType_ERROR,
"CF: invalid configuration parameter id %d received", param_id);
goto err_out;
}
if (chan_num >= CF_NUM_CHANNELS)
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_GETSET_CHAN, CFE_EVS_EventType_ERROR,
"CF: invalid configuration channel id %d received", chan_num);
goto err_out;
}
if (is_set)
{
if (item.fn)
{
if (!item.fn(value, chan_num))
{
valid_set = 1;
}
else
{
CFE_EVS_SendEvent(CF_EID_ERR_CMD_GETSET_VALIDATE, CFE_EVS_EventType_ERROR,
"CF: validation for parameter id %d failed", param_id);
}
}
else
{
valid_set = 1;
}
if (valid_set)
{
acc = 0;
CFE_EVS_SendEvent(CF_EID_INF_CMD_GETSET1, CFE_EVS_EventType_INFORMATION,
"CF: setting parameter id %d to %lu", param_id, (unsigned long)value);
/* Store value based on its size */
if (item.size == sizeof(uint32))
{
*((uint32 *)item.ptr) = value;
}
else if (item.size == sizeof(uint16))
{
*((uint16 *)item.ptr) = value;
}
else
{
/* uint8 is the only other option */
*((uint8 *)item.ptr) = value;