@@ -261,7 +261,7 @@ uint8_t Crypto_Prep_Reply(uint8_t *reply, uint8_t appID)
261261 sdls_frame .hdr .shdr = 1 ;
262262 sdls_frame .hdr .appID = appID ;
263263
264- sdls_frame .pdu .hdr .type = 1 ;
264+ sdls_frame .tlv_pdu .hdr .type = 1 ;
265265
266266 // Fill reply with reply header
267267 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)
282282 }
283283
284284 // 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 );
289289
290- sdls_frame .pdu .hdr .type = 0 ;
290+ sdls_frame .tlv_pdu .hdr .type = 0 ;
291291 return count ;
292292}
293293
@@ -409,13 +409,13 @@ int32_t Crypto_PDU(uint8_t *ingest, TC_t *tc_frame)
409409
410410 if (status == CRYPTO_LIB_SUCCESS )
411411 {
412- switch (sdls_frame .pdu .hdr .type )
412+ switch (sdls_frame .tlv_pdu .hdr .type )
413413 {
414414 case PDU_TYPE_COMMAND :
415- switch (sdls_frame .pdu .hdr .uf )
415+ switch (sdls_frame .tlv_pdu .hdr .uf )
416416 {
417417 case PDU_USER_FLAG_FALSE : // CCSDS Defined Command
418- switch (sdls_frame .pdu .hdr .sg )
418+ switch (sdls_frame .tlv_pdu .hdr .sg )
419419 {
420420 case SG_KEY_MGMT : // Key Management Procedure
421421 status = Crypto_SG_KEY_MGMT (ingest , tc_frame );
@@ -435,7 +435,7 @@ int32_t Crypto_PDU(uint8_t *ingest, TC_t *tc_frame)
435435 break ;
436436
437437 case PDU_USER_FLAG_TRUE : // User Defined Command
438- switch (sdls_frame .pdu .hdr .sg )
438+ switch (sdls_frame .tlv_pdu .hdr .sg )
439439 {
440440 default :
441441 status = Crypto_USER_DEFINED_CMD (ingest );
@@ -465,7 +465,7 @@ int32_t Crypto_PDU(uint8_t *ingest, TC_t *tc_frame)
465465int32_t Crypto_SG_KEY_MGMT (uint8_t * ingest , TC_t * tc_frame )
466466{
467467 int status = CRYPTO_LIB_SUCCESS ;
468- switch (sdls_frame .pdu .hdr .pid )
468+ switch (sdls_frame .tlv_pdu .hdr .pid )
469469 {
470470 case PID_OTAR :
471471#ifdef PDU_DEBUG
@@ -523,7 +523,7 @@ int32_t Crypto_SG_KEY_MGMT(uint8_t *ingest, TC_t *tc_frame)
523523int32_t Crypto_SG_SA_MGMT (uint8_t * ingest , TC_t * tc_frame )
524524{
525525 int status = CRYPTO_LIB_SUCCESS ;
526- switch (sdls_frame .pdu .hdr .pid )
526+ switch (sdls_frame .tlv_pdu .hdr .pid )
527527 {
528528 case PID_CREATE_SA :
529529#ifdef PDU_DEBUG
@@ -603,7 +603,7 @@ int32_t Crypto_SG_SA_MGMT(uint8_t *ingest, TC_t *tc_frame)
603603int32_t Crypto_SEC_MON_CTRL (uint8_t * ingest )
604604{
605605 int status = CRYPTO_LIB_SUCCESS ;
606- switch (sdls_frame .pdu .hdr .pid )
606+ switch (sdls_frame .tlv_pdu .hdr .pid )
607607 {
608608 case PID_PING :
609609#ifdef PDU_DEBUG
@@ -659,7 +659,7 @@ int32_t Crypto_SEC_MON_CTRL(uint8_t *ingest)
659659int32_t Crypto_USER_DEFINED_CMD (uint8_t * ingest )
660660{
661661 int status = CRYPTO_LIB_SUCCESS ;
662- switch (sdls_frame .pdu .hdr .pid )
662+ switch (sdls_frame .tlv_pdu .hdr .pid )
663663 {
664664 case PID_IDLE_FRAME_TRIGGER :
665665#ifdef PDU_DEBUG
@@ -773,7 +773,7 @@ int32_t Crypto_Get_Managed_Parameters_For_Gvcid(uint8_t tfvn, uint16_t scid, uin
773773 * @note - 2) By using a defined Virtual Channel ID
774774 * @note Requires this to happen on either SPI_MIN (0) or SPI_MAX (configurable)
775775 **/
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 )
777777{
778778 int32_t status = CRYPTO_LIB_SUCCESS ;
779779 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
828828 sdls_frame .pus .spare = (tc_sdls_processed_frame -> tc_pdu [9 ] & 0x0F );
829829
830830 // 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 =
836836 (tc_sdls_processed_frame -> tc_pdu [11 ] << 8 ) | tc_sdls_processed_frame -> tc_pdu [12 ];
837837
838838 // Subtract headers from total frame length
839839 // 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
840847 if (sdls_frame .hdr .pkt_length <= TLV_DATA_SIZE ) // && (sdls_frame.hdr.pkt_length < max_tlv))
841848 {
842849 for (int x = 13 ; x < (13 + sdls_frame .hdr .pkt_length ); x ++ )
843850 {
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 ];
845852 }
846853 }
847854 else
@@ -854,20 +861,21 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
854861 else
855862 {
856863 // 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 =
862869 (tc_sdls_processed_frame -> tc_pdu [7 ] << 8 ) | tc_sdls_processed_frame -> tc_pdu [8 ];
863870
864871 // Make sure TLV isn't larger than we have allocated, and it is sane given total frame length
865872 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
866874 if ((sdls_frame .hdr .pkt_length < TLV_DATA_SIZE ) && (sdls_frame .hdr .pkt_length < max_tlv ))
867875 {
868876 for (int x = 9 ; x < (9 + sdls_frame .hdr .pkt_length ); x ++ )
869877 {
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 ];
871879 }
872880 }
873881 else
@@ -913,16 +921,16 @@ int32_t Crypto_Process_Extended_Procedure_Pdu(TC_t *tc_sdls_processed_frame, uin
913921#endif
914922 // No Packet HDR or PUS in these frames
915923 // 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 ];
921929 for (int x = 3 ; x < (3 + tc_sdls_processed_frame -> tc_header .fl ); x ++ )
922930 {
923931 // Todo - Consider how this behaves with large OTAR PDUs that are larger than 1 TC in size. Most likely
924932 // 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 ];
926934 }
927935
928936#ifdef CCSDS_DEBUG
0 commit comments