@@ -261,7 +261,7 @@ uint8_t Crypto_Prep_Reply(uint8_t *reply, uint8_t appID)
261
261
sdls_frame .hdr .shdr = 1 ;
262
262
sdls_frame .hdr .appID = appID ;
263
263
264
- sdls_frame .pdu .hdr .type = 1 ;
264
+ sdls_frame .tlv_pdu .hdr .type = 1 ;
265
265
266
266
// Fill reply with reply header
267
267
reply [count ++ ] = (sdls_frame .hdr .pvn << 5 ) | (sdls_frame .hdr .type << 4 ) | (sdls_frame .hdr .shdr << 3 ) |
@@ -282,12 +282,12 @@ uint8_t Crypto_Prep_Reply(uint8_t *reply, uint8_t appID)
282
282
}
283
283
284
284
// Fill reply with Tag and Length
285
- reply [count ++ ] = (sdls_frame .pdu .hdr .type << 7 ) | (sdls_frame .pdu .hdr .uf << 6 ) | (sdls_frame .pdu .hdr .sg << 4 ) |
286
- (sdls_frame .pdu .hdr .pid );
287
- reply [count ++ ] = (sdls_frame .pdu .hdr .pdu_len & 0xFF00 ) >> 8 ;
288
- reply [count ++ ] = (sdls_frame .pdu .hdr .pdu_len & 0x00FF );
285
+ reply [count ++ ] = (sdls_frame .tlv_pdu .hdr .type << 7 ) | (sdls_frame .tlv_pdu .hdr .uf << 6 ) | (sdls_frame .tlv_pdu .hdr .sg << 4 ) |
286
+ (sdls_frame .tlv_pdu .hdr .pid );
287
+ reply [count ++ ] = (sdls_frame .tlv_pdu .hdr .pdu_len & 0xFF00 ) >> 8 ;
288
+ reply [count ++ ] = (sdls_frame .tlv_pdu .hdr .pdu_len & 0x00FF );
289
289
290
- sdls_frame .pdu .hdr .type = 0 ;
290
+ sdls_frame .tlv_pdu .hdr .type = 0 ;
291
291
return count ;
292
292
}
293
293
@@ -409,13 +409,13 @@ int32_t Crypto_PDU(uint8_t *ingest, TC_t *tc_frame)
409
409
410
410
if (status == CRYPTO_LIB_SUCCESS )
411
411
{
412
- switch (sdls_frame .pdu .hdr .type )
412
+ switch (sdls_frame .tlv_pdu .hdr .type )
413
413
{
414
414
case PDU_TYPE_COMMAND :
415
- switch (sdls_frame .pdu .hdr .uf )
415
+ switch (sdls_frame .tlv_pdu .hdr .uf )
416
416
{
417
417
case PDU_USER_FLAG_FALSE : // CCSDS Defined Command
418
- switch (sdls_frame .pdu .hdr .sg )
418
+ switch (sdls_frame .tlv_pdu .hdr .sg )
419
419
{
420
420
case SG_KEY_MGMT : // Key Management Procedure
421
421
status = Crypto_SG_KEY_MGMT (ingest , tc_frame );
@@ -435,7 +435,7 @@ int32_t Crypto_PDU(uint8_t *ingest, TC_t *tc_frame)
435
435
break ;
436
436
437
437
case PDU_USER_FLAG_TRUE : // User Defined Command
438
- switch (sdls_frame .pdu .hdr .sg )
438
+ switch (sdls_frame .tlv_pdu .hdr .sg )
439
439
{
440
440
default :
441
441
status = Crypto_USER_DEFINED_CMD (ingest );
@@ -465,7 +465,7 @@ int32_t Crypto_PDU(uint8_t *ingest, TC_t *tc_frame)
465
465
int32_t Crypto_SG_KEY_MGMT (uint8_t * ingest , TC_t * tc_frame )
466
466
{
467
467
int status = CRYPTO_LIB_SUCCESS ;
468
- switch (sdls_frame .pdu .hdr .pid )
468
+ switch (sdls_frame .tlv_pdu .hdr .pid )
469
469
{
470
470
case PID_OTAR :
471
471
#ifdef PDU_DEBUG
@@ -523,7 +523,7 @@ int32_t Crypto_SG_KEY_MGMT(uint8_t *ingest, TC_t *tc_frame)
523
523
int32_t Crypto_SG_SA_MGMT (uint8_t * ingest , TC_t * tc_frame )
524
524
{
525
525
int status = CRYPTO_LIB_SUCCESS ;
526
- switch (sdls_frame .pdu .hdr .pid )
526
+ switch (sdls_frame .tlv_pdu .hdr .pid )
527
527
{
528
528
case PID_CREATE_SA :
529
529
#ifdef PDU_DEBUG
@@ -603,7 +603,7 @@ int32_t Crypto_SG_SA_MGMT(uint8_t *ingest, TC_t *tc_frame)
603
603
int32_t Crypto_SEC_MON_CTRL (uint8_t * ingest )
604
604
{
605
605
int status = CRYPTO_LIB_SUCCESS ;
606
- switch (sdls_frame .pdu .hdr .pid )
606
+ switch (sdls_frame .tlv_pdu .hdr .pid )
607
607
{
608
608
case PID_PING :
609
609
#ifdef PDU_DEBUG
@@ -659,7 +659,7 @@ int32_t Crypto_SEC_MON_CTRL(uint8_t *ingest)
659
659
int32_t Crypto_USER_DEFINED_CMD (uint8_t * ingest )
660
660
{
661
661
int status = CRYPTO_LIB_SUCCESS ;
662
- switch (sdls_frame .pdu .hdr .pid )
662
+ switch (sdls_frame .tlv_pdu .hdr .pid )
663
663
{
664
664
case PID_IDLE_FRAME_TRIGGER :
665
665
#ifdef PDU_DEBUG
@@ -773,7 +773,7 @@ int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uin
773
773
* @note - 2) By using a defined Virtual Channel ID
774
774
* @note Requires this to happen on either SPI_MIN (0) or SPI_MAX (configurable)
775
775
**/
776
- int32_t Crypto_Process_Extended_Procedure_Pdu (TC_t * tc_sdls_processed_frame , uint8_t * ingest )
776
+ int32_t Crypto_Process_Extended_Procedure_Pdu (TC_t * tc_sdls_processed_frame , uint8_t * ingest , uint16_t len_ingest )
777
777
{
778
778
int32_t status = CRYPTO_LIB_SUCCESS ;
779
779
ingest = ingest ; // Suppress unused variable error depending on build
@@ -828,20 +828,27 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
828
828
sdls_frame .pus .spare = (tc_sdls_processed_frame -> tc_pdu [9 ] & 0x0F );
829
829
830
830
// SDLS TLV PDU
831
- sdls_frame .pdu .hdr .type = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x80 ) >> 7 ;
832
- sdls_frame .pdu .hdr .uf = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x40 ) >> 6 ;
833
- sdls_frame .pdu .hdr .sg = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x30 ) >> 4 ;
834
- sdls_frame .pdu .hdr .pid = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x0F );
835
- sdls_frame .pdu .hdr .pdu_len =
831
+ sdls_frame .tlv_pdu .hdr .type = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x80 ) >> 7 ;
832
+ sdls_frame .tlv_pdu .hdr .uf = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x40 ) >> 6 ;
833
+ sdls_frame .tlv_pdu .hdr .sg = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x30 ) >> 4 ;
834
+ sdls_frame .tlv_pdu .hdr .pid = (tc_sdls_processed_frame -> tc_pdu [10 ] & 0x0F );
835
+ sdls_frame .tlv_pdu .hdr .pdu_len =
836
836
(tc_sdls_processed_frame -> tc_pdu [11 ] << 8 ) | tc_sdls_processed_frame -> tc_pdu [12 ];
837
837
838
838
// Subtract headers from total frame length
839
839
// uint16_t max_tlv = tc_sdls_processed_frame->tc_header.fl - CCSDS_HDR_SIZE - CCSDS_PUS_SIZE - SDLS_TLV_HDR_SIZE;
840
+ #ifdef CCSDS_DEBUG
841
+ printf ("Printing lengths for sanity check:\n" );
842
+ printf ("\t Telecommand PDU Length: %d \n" , tc_sdls_processed_frame -> tc_pdu_len );
843
+ printf ("\t Received TLV Length: %d \n" , 1 );
844
+ printf ("\t Max possible TLV Length: %d \n" , 1 );
845
+ printf ("\t Calculated TLV length based on " );
846
+ #endif
840
847
if (sdls_frame .hdr .pkt_length <= TLV_DATA_SIZE ) // && (sdls_frame.hdr.pkt_length < max_tlv))
841
848
{
842
849
for (int x = 13 ; x < (13 + sdls_frame .hdr .pkt_length ); x ++ )
843
850
{
844
- sdls_frame .pdu .data [x - 13 ] = tc_sdls_processed_frame -> tc_pdu [x ];
851
+ sdls_frame .tlv_pdu .data [x - 13 ] = tc_sdls_processed_frame -> tc_pdu [x ];
845
852
}
846
853
}
847
854
else
@@ -854,20 +861,21 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
854
861
else
855
862
{
856
863
// SDLS TLV PDU
857
- sdls_frame .pdu .hdr .type = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x80 ) >> 7 ;
858
- sdls_frame .pdu .hdr .uf = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x40 ) >> 6 ;
859
- sdls_frame .pdu .hdr .sg = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x30 ) >> 4 ;
860
- sdls_frame .pdu .hdr .pid = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x0F );
861
- sdls_frame .pdu .hdr .pdu_len =
864
+ sdls_frame .tlv_pdu .hdr .type = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x80 ) >> 7 ;
865
+ sdls_frame .tlv_pdu .hdr .uf = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x40 ) >> 6 ;
866
+ sdls_frame .tlv_pdu .hdr .sg = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x30 ) >> 4 ;
867
+ sdls_frame .tlv_pdu .hdr .pid = (tc_sdls_processed_frame -> tc_pdu [6 ] & 0x0F );
868
+ sdls_frame .tlv_pdu .hdr .pdu_len =
862
869
(tc_sdls_processed_frame -> tc_pdu [7 ] << 8 ) | tc_sdls_processed_frame -> tc_pdu [8 ];
863
870
864
871
// Make sure TLV isn't larger than we have allocated, and it is sane given total frame length
865
872
uint16_t max_tlv = tc_sdls_processed_frame -> tc_header .fl - CCSDS_HDR_SIZE - SDLS_TLV_HDR_SIZE ;
873
+ len_ingest = len_ingest ; // suppress error for now
866
874
if ((sdls_frame .hdr .pkt_length < TLV_DATA_SIZE ) && (sdls_frame .hdr .pkt_length < max_tlv ))
867
875
{
868
876
for (int x = 9 ; x < (9 + sdls_frame .hdr .pkt_length ); x ++ )
869
877
{
870
- sdls_frame .pdu .data [x - 9 ] = tc_sdls_processed_frame -> tc_pdu [x ];
878
+ sdls_frame .tlv_pdu .data [x - 9 ] = tc_sdls_processed_frame -> tc_pdu [x ];
871
879
}
872
880
}
873
881
else
@@ -913,16 +921,16 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
913
921
#endif
914
922
// No Packet HDR or PUS in these frames
915
923
// SDLS TLV PDU
916
- sdls_frame .hdr .type = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x80 ) >> 7 ;
917
- sdls_frame .pdu .hdr .uf = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x40 ) >> 6 ;
918
- sdls_frame .pdu .hdr .sg = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x30 ) >> 4 ;
919
- sdls_frame .pdu .hdr .pid = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x0F );
920
- sdls_frame .pdu .hdr .pdu_len = (tc_sdls_processed_frame -> tc_pdu [1 ] << 8 ) | tc_sdls_processed_frame -> tc_pdu [2 ];
924
+ sdls_frame .tlv_pdu . hdr .type = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x80 ) >> 7 ;
925
+ sdls_frame .tlv_pdu .hdr .uf = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x40 ) >> 6 ;
926
+ sdls_frame .tlv_pdu .hdr .sg = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x30 ) >> 4 ;
927
+ sdls_frame .tlv_pdu .hdr .pid = (tc_sdls_processed_frame -> tc_pdu [0 ] & 0x0F );
928
+ sdls_frame .tlv_pdu .hdr .pdu_len = (tc_sdls_processed_frame -> tc_pdu [1 ] << 8 ) | tc_sdls_processed_frame -> tc_pdu [2 ];
921
929
for (int x = 3 ; x < (3 + tc_sdls_processed_frame -> tc_header .fl ); x ++ )
922
930
{
923
931
// Todo - Consider how this behaves with large OTAR PDUs that are larger than 1 TC in size. Most likely
924
932
// fails. Must consider Uplink Sessions (sequence numbers).
925
- sdls_frame .pdu .data [x - 3 ] = tc_sdls_processed_frame -> tc_pdu [x ];
933
+ sdls_frame .tlv_pdu .data [x - 3 ] = tc_sdls_processed_frame -> tc_pdu [x ];
926
934
}
927
935
928
936
#ifdef CCSDS_DEBUG
0 commit comments