Skip to content

Commit 42c9a1c

Browse files
authored
Merge pull request #338 from nasa/209-aostm-clsw-fsr-support
209 aostm clsw fsr support
2 parents 51a71a6 + 32c2c12 commit 42c9a1c

File tree

12 files changed

+281
-85
lines changed

12 files changed

+281
-85
lines changed

include/crypto.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ void Crypto_TC_Handle_Padding(uint32_t pkcs_padding, SecurityAssociation_t *s
159159
uint16_t *index);
160160
int32_t Crypto_TC_Set_IV(SecurityAssociation_t *sa_ptr, uint8_t *p_new_enc_frame, uint16_t *index);
161161

162+
// OCF
163+
uint32_t Crypto_Get_FSR();
164+
void Crypto_Set_FSR(uint8_t *p_ingest, uint16_t byte_idx, uint16_t pdu_len, SecurityAssociation_t *sa_ptr);
165+
162166
// Telemetry (TM)
163167
extern int32_t Crypto_TM_ApplySecurity(uint8_t *pTfBuffer);
164168
extern int32_t Crypto_TM_ProcessSecurity(uint8_t *p_ingest, uint16_t len_ingest, uint8_t **pp_processed_frame,
@@ -221,7 +225,7 @@ extern int32_t Crypto_increment(uint8_t *num, int length);
221225
int32_t Crypto_Get_tmLength(int len);
222226
uint8_t Crypto_Is_AEAD_Algorithm(uint32_t cipher_suite_id);
223227
void Crypto_TM_updatePDU(uint8_t *ingest, int len_ingest);
224-
void Crypto_TM_updateOCF(void);
228+
void Crypto_TM_updateOCF(Telemetry_Frame_Ocf_Fsr_t *report, TM_t *tm_frame);
225229
uint8_t *Crypto_Prepare_TC_AAD(uint8_t *buffer, uint16_t len_aad, uint8_t *abm_buffer);
226230
uint32_t Crypto_Prepare_TM_AAD(const uint8_t *buffer, uint16_t len_aad, const uint8_t *abm_buffer, uint8_t *aad);
227231
uint32_t Crypto_Prepare_AOS_AAD(const uint8_t *buffer, uint16_t len_aad, const uint8_t *abm_buffer, uint8_t *aad);
@@ -325,10 +329,12 @@ extern CryptographyInterface cryptography_if;
325329
extern SadbMariaDBConfig_t *sa_mariadb_config;
326330
extern GvcidManagedParameters_t *gvcid_managed_parameters;
327331
extern GvcidManagedParameters_t *current_managed_parameters;
332+
328333
// OCF
329-
extern uint8_t ocf;
330-
extern SDLS_FSR_t report;
331-
extern Telemetry_Frame_Clcw_t clcw;
334+
extern uint8_t ocf;
335+
extern Telemetry_Frame_Ocf_Fsr_t report;
336+
extern Telemetry_Frame_Ocf_Clcw_t clcw;
337+
332338
// Flags
333339
extern SDLS_MC_LOG_RPLY_t log_summary;
334340
extern SDLS_MC_DUMP_BLK_RPLY_t mc_log;

include/crypto_print.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ void Crypto_tmPrint(TM_t *tm_frame);
4848
* @param clcw: Telemetry_Frame_Clcw_t*
4949
* Prints the contents of the clcw
5050
**/
51-
void Crypto_clcwPrint(Telemetry_Frame_Clcw_t *clcw);
51+
void Crypto_clcwPrint(Telemetry_Frame_Ocf_Clcw_t *clcw);
5252

5353
/**
5454
* @brief Function: Crypto_fsrPrint
5555
* @param report: SDLS_FSR_t*
5656
* Prints the contents of current FSR in memory
5757
**/
58-
void Crypto_fsrPrint(SDLS_FSR_t *report);
58+
void Crypto_fsrPrint(Telemetry_Frame_Ocf_Fsr_t *report);
5959

6060
/**
6161
* @brief Function: Crypto_ccsdsPrint

include/crypto_structs.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -346,47 +346,49 @@ typedef struct
346346
#define CCSDS_SIZE (sizeof(CCSDS_t))
347347

348348
/*
349-
** Operational Control Field definition
349+
** Operational Control Field definitions
350350
** Telemetry frames can reply with either of these in their OCF field:
351351
** 1) A Communications Control Link Word -or-
352352
** 2) A Frame Security Report
353353
*/
354354

355355
// INFO: This is the Communications Link Control Word register format
356+
// Ref: Version 000, CCSDS 232.0-B-4, Oct 2021
356357
typedef struct
357358
{
358359
uint8_t cwt : 1; // Control Word Type "0"
359360
uint8_t cvn : 2; // CLCW Version Number "00"
360361
uint8_t sf : 3; // Status Field
361362
uint8_t cie : 2; // COP In Effect
362363
uint8_t vci : 6; // Virtual Channel Identification
363-
uint8_t spare0 : 2; // Reserved Spare
364-
uint8_t nrfa : 1; // No RF Avaliable Flag
365-
uint8_t nbl : 1; // No Bit Lock Flag
366-
uint8_t lo : 1; // Lock-Out Flag
367-
uint8_t wait : 1; // Wait Flag
368-
uint8_t rt : 1; // Retransmit Flag
364+
uint8_t spare0 : 2; // Reserved Spare "00"
365+
uint8_t nrfaf : 1; // No RF Avaliable Flag
366+
uint8_t nblf : 1; // No Bit Lock Flag
367+
uint8_t lof : 1; // Lock-Out Flag
368+
uint8_t waitf : 1; // Wait Flag
369+
uint8_t rtf : 1; // Retransmit Flag
369370
uint8_t fbc : 2; // FARM-B Counter
370-
uint8_t spare1 : 1; // Reserved Spare
371+
uint8_t spare1 : 1; // Reserved Spare "0"
371372
uint8_t rv : 8; // Report Value
372-
} Telemetry_Frame_Clcw_t;
373+
} Telemetry_Frame_Ocf_Clcw_t;
373374

374-
#define TM_FRAME_CLCW_SIZE (sizeof(Telemetry_Frame_Clcw_t))
375+
#define TELEMETRY_FRAME_OCF_CLCW_SIZE (sizeof(Telemetry_Frame_Ocf_Clcw_t))
375376

376377
// INFO: This is the Frame Security Report register format
378+
// Ref: Version 100, CCSDS 355.1-B-1, Feb 2020
377379
typedef struct
378380
{
379381
uint8_t cwt : 1; // Control Word Type "1"
380382
uint8_t fvn : 3; // FSR Version Number "100"
381383
uint8_t af : 1; // Alarm Flag
382384
uint8_t bsnf : 1; // Bad Sequence Number Flag
383-
uint8_t bmf : 1; // Bad Mac Flag
385+
uint8_t bmacf : 1; // Bad Mac Flag
384386
uint8_t bsaf : 1; // Bad Security Association Flag
385387
uint16_t lspi : 16; // Last SPI Used
386-
uint8_t snv : 8; // Sequence Number Value (LSB)
387-
} Telemetry_Frame_Fsr_t;
388+
uint8_t snval : 8; // Sequence Number Value (LSB)
389+
} Telemetry_Frame_Ocf_Fsr_t;
388390

389-
#define TELEMETRY_FRAME_OCF_SIZE (sizeof(Telemetry_Frame_Fsr_t))
391+
#define TELEMETRY_FRAME_OCF_FSR_SIZE (sizeof(Telemetry_Frame_Ocf_Fsr_t))
390392

391393
/*
392394
** Telemetry (TM) Definitions

src/core/crypto.c

Lines changed: 90 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ uint8_t aos_frame[AOS_MAX_FRAME_SIZE]; // AOS Global Frame
4646
AOS_FramePrimaryHeader_t aos_frame_pri_hdr; // Used to reduce bit math duplication
4747
AOS_FrameSecurityHeader_t aos_frame_sec_hdr; // Used to reduce bit math duplication
4848
// OCF
49-
uint8_t ocf = 0;
50-
SDLS_FSR_t report;
51-
Telemetry_Frame_Clcw_t clcw;
49+
uint8_t ocf = 0;
50+
Telemetry_Frame_Ocf_Fsr_t report;
51+
Telemetry_Frame_Ocf_Clcw_t clcw;
5252
// Flags
5353
SDLS_MC_LOG_RPLY_t log_summary;
5454
SDLS_MC_DUMP_BLK_RPLY_t mc_log;
@@ -1120,3 +1120,90 @@ int32_t Crypto_Get_ACS_Algo_Keylen(uint8_t algo)
11201120

11211121
return retval;
11221122
}
1123+
1124+
/**
1125+
* @brief: Function: Crypto_Get_Security_Header_Length
1126+
* Return Security Header Length
1127+
* @param sa_ptr: SecurityAssociation_t*
1128+
**/
1129+
int32_t Crypto_Get_Security_Header_Length(SecurityAssociation_t *sa_ptr)
1130+
{
1131+
/* Narrator's Note: Leaving this here for future work
1132+
** eventually we need a way to reconcile cryptolib managed parameters with TO managed parameters
1133+
GvcidManagedParameters_t* temp_current_managed_parameters = NULL;
1134+
Crypto_Get_Managed_Parameters_For_Gvcid(tfvn, scid, vcid,
1135+
gvcid_managed_parameters, temp_current_managed_parameters);
1136+
*/
1137+
1138+
if (!sa_ptr)
1139+
{
1140+
#ifdef DEBUG
1141+
printf(KRED "Get_Security_Header_Length passed Null SA!\n" RESET);
1142+
#endif
1143+
return CRYPTO_LIB_ERR_NULL_SA;
1144+
}
1145+
uint16_t securityHeaderLength = 2; // Start with SPI
1146+
1147+
securityHeaderLength += sa_ptr->shivf_len + sa_ptr->shsnf_len + sa_ptr->shplf_len;
1148+
1149+
return securityHeaderLength;
1150+
}
1151+
1152+
/**
1153+
* @brief: Function: Crypto_Get_Security_Trailer_Length
1154+
* Return Security Trailer Length
1155+
* @param sa_ptr: SecurityAssociation_t*
1156+
**/
1157+
int32_t Crypto_Get_Security_Trailer_Length(SecurityAssociation_t *sa_ptr)
1158+
{
1159+
if (!sa_ptr)
1160+
{
1161+
#ifdef DEBUG
1162+
printf(KRED "Get_Trailer_Trailer_Length passed Null SA!\n" RESET);
1163+
#endif
1164+
return CRYPTO_LIB_ERR_NULL_SA;
1165+
}
1166+
uint16_t securityTrailerLength = 0;
1167+
1168+
securityTrailerLength = sa_ptr->stmacf_len;
1169+
1170+
return securityTrailerLength;
1171+
}
1172+
1173+
void Crypto_Set_FSR(uint8_t *p_ingest, uint16_t byte_idx, uint16_t pdu_len, SecurityAssociation_t *sa_ptr)
1174+
{
1175+
if (current_managed_parameters_struct.has_ocf == TM_HAS_OCF || current_managed_parameters_struct.has_ocf == AOS_HAS_OCF)
1176+
{
1177+
Telemetry_Frame_Ocf_Fsr_t temp_report;
1178+
byte_idx += (pdu_len + sa_ptr->stmacf_len);
1179+
temp_report.cwt = (p_ingest[byte_idx] >> 7) & 0x01;
1180+
temp_report.fvn = (p_ingest[byte_idx] >> 4) & 0x07;
1181+
temp_report.af = (p_ingest[byte_idx] >> 3) & 0x01;
1182+
temp_report.bsnf = (p_ingest[byte_idx] >> 2) & 0x01;
1183+
temp_report.bmacf = (p_ingest[byte_idx] >> 1) & 0x01;
1184+
temp_report.bsaf = (p_ingest[byte_idx] & 0x01);
1185+
byte_idx += 1;
1186+
temp_report.lspi = (p_ingest[byte_idx] << 8) | (p_ingest[byte_idx + 1]);
1187+
byte_idx += 2;
1188+
temp_report.snval = (p_ingest[byte_idx]);
1189+
byte_idx++;
1190+
report = temp_report;
1191+
#ifdef DEBUG
1192+
Crypto_fsrPrint(&report);
1193+
#endif
1194+
}
1195+
}
1196+
1197+
uint32_t Crypto_Get_FSR()
1198+
{
1199+
uint32_t fsr;
1200+
fsr = (report.cwt << 31) | // bit(s) 1
1201+
(report.fvn << 28) | // bit(s) 2-4
1202+
(report.af << 27) | // bit(s) 5
1203+
(report.bsnf << 26) | // bit(s) 6
1204+
(report.bmacf << 25) | // bit(s) 7
1205+
(report.bsaf << 24) | // bit(s) 8
1206+
(report.lspi << 8) | // bit(s) 9-24
1207+
(report.snval << 0); // bit(s) 25-32
1208+
return fsr;
1209+
}

src/core/crypto_aos.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ int32_t Crypto_AOS_ProcessSecurity(uint8_t *p_ingest, uint16_t len_ingest, uint8
11811181
{
11821182
mac_loc = byte_idx + pdu_len;
11831183
}
1184+
Crypto_Set_FSR(p_ingest, byte_idx, pdu_len, sa_ptr);
11841185

11851186
#ifdef AOS_DEBUG
11861187
printf(KYEL "Index / data location starts at: %d\n" RESET, byte_idx);

src/core/crypto_config.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -828,23 +828,23 @@ void Crypto_Local_Init(void)
828828
clcw.cie = 1; // COP In Effect
829829
clcw.vci = 0; // Virtual Channel Identification
830830
clcw.spare0 = 0; // Reserved Spare
831-
clcw.nrfa = 0; // No RF Avaliable Flag
832-
clcw.nbl = 0; // No Bit Lock Flag
833-
clcw.lo = 0; // Lock-Out Flag
834-
clcw.wait = 0; // Wait Flag
835-
clcw.rt = 0; // Retransmit Flag
831+
clcw.nrfaf = 0; // No RF Avaliable Flag
832+
clcw.nblf = 0; // No Bit Lock Flag
833+
clcw.lof = 0; // Lock-Out Flag
834+
clcw.waitf = 0; // Wait Flag
835+
clcw.rtf = 0; // Retransmit Flag
836836
clcw.fbc = 0; // FARM-B Counter
837837
clcw.spare1 = 0; // Reserved Spare
838838
clcw.rv = 0; // Report Value
839839

840840
// Initialize Frame Security Report
841841
report.cwt = 1; // Control Word Type "0b1""
842-
report.vnum = 4; // FSR Version "0b100""
842+
report.fvn = 4; // FSR Version "0b100""
843843
report.af = 0; // Alarm Field
844844
report.bsnf = 0; // Bad SN Flag
845845
report.bmacf = 0; // Bad MAC Flag
846-
report.ispif = 0; // Invalid SPI Flag
847-
report.lspiu = 0; // Last SPI Used
846+
report.bsaf = 0; // Invalid SPI Flag
847+
report.lspi = 0; // Last SPI Used
848848
report.snval = 0; // SN Value (LSB)
849849
}
850850

src/core/crypto_mc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,6 @@ int32_t Crypto_MC_resetalarm(void)
349349
report.af = 0;
350350
report.bsnf = 0;
351351
report.bmacf = 0;
352-
report.ispif = 0;
352+
report.bsaf = 0;
353353
return CRYPTO_LIB_SUCCESS;
354354
}

src/core/crypto_print.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ void Crypto_Print_Sdls_Ep_Reply(void)
126126
/**
127127
* @brief Function: Crypto_clcwPrint
128128
* Prints the current CLCW in memory.
129-
* @param clcw: Telemetry_Frame_Clcw_t*
129+
* @param clcw: Telemetry_Frame_Ocf_Clcw_t*
130130
**/
131-
void Crypto_clcwPrint(Telemetry_Frame_Clcw_t *clcw)
131+
void Crypto_clcwPrint(Telemetry_Frame_Ocf_Clcw_t *clcw)
132132
{
133133
printf("Current CLCW in memory is: \n");
134134
printf("\t cwt = 0x%01x \n", clcw->cwt);
@@ -137,11 +137,11 @@ void Crypto_clcwPrint(Telemetry_Frame_Clcw_t *clcw)
137137
printf("\t cie = 0x%01x \n", clcw->cie);
138138
printf("\t vci = 0x%02x \n", clcw->vci);
139139
printf("\t spare0 = 0x%01x \n", clcw->spare0);
140-
printf("\t nrfa = 0x%01x \n", clcw->nrfa);
141-
printf("\t nbl = 0x%01x \n", clcw->nbl);
142-
printf("\t lo = 0x%01x \n", clcw->lo);
143-
printf("\t wait = 0x%01x \n", clcw->wait);
144-
printf("\t rt = 0x%01x \n", clcw->rt);
140+
printf("\t nrfaf = 0x%01x \n", clcw->nrfaf);
141+
printf("\t nblf = 0x%01x \n", clcw->nblf);
142+
printf("\t lof = 0x%01x \n", clcw->lof);
143+
printf("\t waitf = 0x%01x \n", clcw->waitf);
144+
printf("\t rtf = 0x%01x \n", clcw->rtf);
145145
printf("\t fbc = 0x%01x \n", clcw->fbc);
146146
printf("\t spare1 = 0x%01x \n", clcw->spare1);
147147
printf("\t rv = 0x%02x \n", clcw->rv);
@@ -151,18 +151,18 @@ void Crypto_clcwPrint(Telemetry_Frame_Clcw_t *clcw)
151151
/**
152152
* @brief Function: Crypto_fsrPrint
153153
* Prints the current FSR in memory.
154-
* @param report: SDLS_FSR_t*
154+
* @param report: Telemetry_Frame_Ocf_Fsr_t*
155155
**/
156-
void Crypto_fsrPrint(SDLS_FSR_t *report)
156+
void Crypto_fsrPrint(Telemetry_Frame_Ocf_Fsr_t *report)
157157
{
158158
printf("Current FSR in memory is: \n");
159159
printf("\t cwt = 0x%01x \n", report->cwt);
160-
printf("\t vnum = 0x%01x \n", report->vnum);
160+
printf("\t fvn = 0x%01x \n", report->fvn);
161161
printf("\t af = 0x%01x \n", report->af);
162162
printf("\t bsnf = 0x%01x \n", report->bsnf);
163163
printf("\t bmacf = 0x%01x \n", report->bmacf);
164-
printf("\t ispif = 0x%01x \n", report->ispif);
165-
printf("\t lspiu = 0x%01x \n", report->lspiu);
164+
printf("\t bsaf = 0x%01x \n", report->bsaf);
165+
printf("\t lspi = 0x%01x \n", report->lspi);
166166
printf("\t snval = 0x%01x \n", report->snval);
167167
printf("\n");
168168
}

0 commit comments

Comments
 (0)