From 06b91f00b90fed97963fbfeb8ceafaee568dedb7 Mon Sep 17 00:00:00 2001 From: Donovan Russell Ice Date: Fri, 9 Jan 2026 15:21:46 -0500 Subject: [PATCH 1/2] Modify mariadb table name usage, modify standalone for new API --- include/crypto.h | 2 +- src/core/crypto.c | 2 +- src/core/crypto_aos.c | 4 +- src/core/crypto_config.c | 5 +- src/core/crypto_mc.c | 2 +- src/core/crypto_tc.c | 4 +- src/core/crypto_tm.c | 4 +- src/core/crypto_user.c | 2 +- support/standalone/standalone.c | 100 +++++++++++++++++--------------- support/standalone/standalone.h | 4 +- 10 files changed, 69 insertions(+), 60 deletions(-) diff --git a/include/crypto.h b/include/crypto.h index 599edaf5..398dffb7 100644 --- a/include/crypto.h +++ b/include/crypto.h @@ -329,7 +329,7 @@ extern uint8_t parity[4]; // Used in FHECF calc // Global configuration structs extern CryptoConfig_t crypto_config; extern SadbMariaDBConfig_t *sa_mariadb_config; -extern char *mariadb_table_name; +extern char mariadb_table_name[26]; extern CryptographyKmcCryptoServiceConfig_t *cryptography_kmc_crypto_config; extern CamConfig_t *cam_config; extern GvcidManagedParameters_t *gvcid_managed_parameters; diff --git a/src/core/crypto.c b/src/core/crypto.c index f452a0a4..01f5fc4c 100644 --- a/src/core/crypto.c +++ b/src/core/crypto.c @@ -73,7 +73,7 @@ uint8_t parity[RS_PARITY]; uint32_t crc32Table[CRC32TBL_SIZE]; uint16_t crc16Table[CRC16TBL_SIZE]; // Mariadb -char *mariadb_table_name = "security_associations"; +char mariadb_table_name[] = "security_associations"; /* ** Assisting Functions diff --git a/src/core/crypto_aos.c b/src/core/crypto_aos.c index 0d6aa8f0..50745195 100644 --- a/src/core/crypto_aos.c +++ b/src/core/crypto_aos.c @@ -108,7 +108,7 @@ int32_t Crypto_AOS_ApplySecurity(uint8_t *pTfBuffer, uint16_t len_ingest) if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_AOS_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_AOS_TABLE_NAME, sizeof(mariadb_table_name)); } status = sa_if->sa_get_operational_sa_from_gvcid(tfvn, scid, vcid, 0, &sa_ptr); @@ -972,7 +972,7 @@ int32_t Crypto_AOS_ProcessSecurity(uint8_t *p_ingest, uint16_t len_ingest, AOS_t if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_AOS_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_AOS_TABLE_NAME, sizeof(mariadb_table_name)); } status = sa_if->sa_get_from_spi(spi, &sa_ptr); // If no valid SPI, return diff --git a/src/core/crypto_config.c b/src/core/crypto_config.c index 0d46955c..129ca013 100644 --- a/src/core/crypto_config.c +++ b/src/core/crypto_config.c @@ -104,7 +104,8 @@ int32_t Crypto_SC_Init(void) SecurityAssociation_t *sa_ptr = NULL; if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TC_TABLE_NAME; + //mariadb_table_name = MARIADB_TC_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TC_TABLE_NAME, sizeof(mariadb_table_name)); } sa_if->sa_get_from_spi(1, &sa_ptr); sa_ptr->gvcid_blk.vcid = 0; @@ -119,7 +120,7 @@ int32_t Crypto_SC_Init(void) sa_ptr->iv_len = 0; if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TM_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TM_TABLE_NAME, sizeof(mariadb_table_name)); } sa_if->sa_get_from_spi(5, &sa_ptr); sa_ptr->sa_state = SA_OPERATIONAL; diff --git a/src/core/crypto_mc.c b/src/core/crypto_mc.c index 3a75fbbf..935ce629 100644 --- a/src/core/crypto_mc.c +++ b/src/core/crypto_mc.c @@ -294,7 +294,7 @@ int32_t Crypto_SA_readARSN(uint8_t *ingest) // TODO: This is not correct if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TC_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TC_TABLE_NAME, sizeof(mariadb_table_name)); } status = sa_if->sa_get_from_spi(spi, &sa_ptr); diff --git a/src/core/crypto_tc.c b/src/core/crypto_tc.c index 5d07c9e2..4c4b2a2c 100644 --- a/src/core/crypto_tc.c +++ b/src/core/crypto_tc.c @@ -842,7 +842,7 @@ int32_t Crytpo_TC_Validate_TC_Temp_Header(const uint16_t in_frame_length, TC_Fra } if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TC_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TC_TABLE_NAME, sizeof(mariadb_table_name)); } status = sa_if->sa_get_operational_sa_from_gvcid(temp_tc_header.tfvn, temp_tc_header.scid, temp_tc_header.vcid, *map_id, sa_ptr); @@ -1831,7 +1831,7 @@ uint32_t Crypto_TC_Sanity_Validations(TC_t *tc_sdls_processed_frame, SecurityAss if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TC_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TC_TABLE_NAME, sizeof(mariadb_table_name)); } status = sa_if->sa_get_from_spi(tc_sdls_processed_frame->tc_sec_header.spi, sa_ptr); // If no valid SPI, return diff --git a/src/core/crypto_tm.c b/src/core/crypto_tm.c index 91c8967e..915d28e4 100644 --- a/src/core/crypto_tm.c +++ b/src/core/crypto_tm.c @@ -823,7 +823,7 @@ int32_t Crypto_TM_ApplySecurity(uint8_t *pTfBuffer, uint16_t len_ingest) if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TM_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TM_TABLE_NAME, sizeof(mariadb_table_name)); } status = sa_if->sa_get_operational_sa_from_gvcid(tfvn, scid, vcid, 0, &sa_ptr); @@ -1750,7 +1750,7 @@ int32_t Crypto_TM_ProcessSecurity(uint8_t *p_ingest, uint16_t len_ingest, TM_t * if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TM_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TM_TABLE_NAME, sizeof(mariadb_table_name)); } status = sa_if->sa_get_from_spi(spi, &sa_ptr); } diff --git a/src/core/crypto_user.c b/src/core/crypto_user.c index e127d960..0addb2db 100644 --- a/src/core/crypto_user.c +++ b/src/core/crypto_user.c @@ -177,7 +177,7 @@ int32_t Crypto_User_ModifyVCID(void) // TODO: This is not correct if (crypto_config.sa_type == SA_TYPE_MARIADB) { - mariadb_table_name = MARIADB_TC_TABLE_NAME; + strncpy(mariadb_table_name, MARIADB_TC_TABLE_NAME, sizeof(mariadb_table_name)); } for (i = 0; i < NUM_GVCID; i++) diff --git a/support/standalone/standalone.c b/support/standalone/standalone.c index b4c53e9e..2803df28 100644 --- a/support/standalone/standalone.c +++ b/support/standalone/standalone.c @@ -609,7 +609,7 @@ void *crypto_standalone_tc_apply(void *socks) return tc_read_sock; } -void crypto_standalone_tm_frame(uint8_t *in_data, uint16_t in_length, uint8_t *out_data, uint16_t *out_length, +void crypto_standalone_tm_frame(TM_t *in_data, uint16_t in_length, uint8_t *out_data, uint16_t *out_length, uint16_t spi) { SaInterface sa_if = get_sa_interface_inmemory(); @@ -640,7 +640,7 @@ void crypto_standalone_tm_frame(uint8_t *in_data, uint16_t in_length, uint8_t *o *out_length = (uint16_t)in_length - header_length - trailer_length; /* TM Header */ - memcpy(out_data, &in_data[header_length], in_length - header_length - trailer_length); + memcpy(out_data, &in_data->tm_header, in_length - header_length - trailer_length); } void crypto_standalone_tm_debug_recv(int32_t status, int tm_process_len, uint8_t *tm_process_in) @@ -670,29 +670,30 @@ void crypto_standalone_tm_debug_process(uint8_t *tm_process_in) } } -void crypto_standalone_spp_telem_or_idle(int32_t *status, uint8_t *tm_ptr, uint16_t *spp_len, udp_interface_t *tm_socks, +void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t *spp_len, udp_interface_t *tm_socks, int *tm_process_len) { udp_info_t *tm_write_sock = &tm_socks->write; - if ((tm_ptr[0] == 0x08) || (tm_ptr[0] == 0x09) || ((tm_ptr[0] == 0x07) && (tm_ptr[1] == 0xff)) || - (tm_ptr[0] == 0x0F && tm_ptr[1] == 0xFD)) + if (((tm_ptr->tm_pdu[0]) == 0x08) || ((tm_ptr->tm_pdu[0]) == 0x09) || (((tm_ptr->tm_pdu[0]) == 0x07) && ((tm_ptr->tm_pdu[1]) == 0xff)) || + ((tm_ptr->tm_pdu[0]) == 0x0F && (tm_ptr->tm_pdu[1]) == 0xFD)) { - *spp_len = (((0xFFFF & tm_ptr[4]) << 8) | tm_ptr[5]) + 7; -#ifdef CRYPTO_STANDALONE_TM_PROCESS_DEBUG - printf("crypto_standalone_tm_process - SPP[%d]: 0x", *spp_len); - for (int i = 0; i < *spp_len; i++) + *spp_len = ((((tm_ptr->tm_pdu[4])) << 8) | (tm_ptr->tm_pdu[5])) + 7; + if (tm_debug) { - printf("%02x", tm_ptr[i]); + printf("crypto_standalone_tm_process - SPP[%d]: 0x", *spp_len); + for (int i = 0; i < *spp_len; i++) + { + printf("%02x", tm_ptr->tm_pdu[i]); + } + printf("\n"); } - printf("\n"); -#endif // Send all SPP telemetry packets // 0x09 for HK/Device TLM Packets (Generic Components) // 0x0FFD = CFDP - if (tm_ptr[0] == 0x08 || tm_ptr[0] == 0x09 || (tm_ptr[0] == 0x0f && tm_ptr[1] == 0xfd)) + if ((tm_ptr->tm_pdu[0]) == 0x08 || (tm_ptr->tm_pdu[0]) == 0x09 || ((tm_ptr->tm_pdu[0]) == 0x0f && (tm_ptr->tm_pdu[1]) == 0xfd)) { - *status = sendto(tm_write_sock->sockfd, tm_ptr, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, + *status = sendto(tm_write_sock->sockfd, tm_ptr->tm_pdu, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, sizeof(tm_write_sock->saddr)); } // Only send idle packets if configured to do so @@ -702,7 +703,7 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, uint8_t *tm_ptr, uint1 // Don't forward idle packets *status = *spp_len; #else - *status = sendto(tm_write_sock->sockfd, tm_ptr, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, + *status = sendto(tm_write_sock->sockfd, tm_ptr->tm_pdu, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, sizeof(tm_write_sock->saddr)); #endif } @@ -715,8 +716,8 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, uint8_t *tm_ptr, uint1 *tm_process_len -= *spp_len; } - else if ((tm_ptr[0] == 0xFF && tm_ptr[1] == 0x48) || (tm_ptr[0] == 0x00 && tm_ptr[1] == 0x00) || - (tm_ptr[0] == 0x02 && tm_ptr[1] == 0x00) || (tm_ptr[0] == 0xFF && tm_ptr[1] == 0xFF)) + else if (((tm_ptr->tm_pdu[0]) == 0xFF && (tm_ptr->tm_pdu[1]) == 0x48) || ((tm_ptr->tm_pdu[0]) == 0x00 && (tm_ptr->tm_pdu[1]) == 0x00) || + ((tm_ptr->tm_pdu[0]) == 0x02 && (tm_ptr->tm_pdu[1]) == 0x00) || ((tm_ptr->tm_pdu[0]) == 0xFF && (tm_ptr->tm_pdu[1]) == 0xFF)) { // TODO: Why 0x0200? // Idle Frame @@ -725,7 +726,7 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, uint8_t *tm_ptr, uint1 // Don't forward idle frame *status = *spp_len; #else - *status = sendto(tm_write_sock->sockfd, tm_ptr, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, + *status = sendto(tm_write_sock->sockfd, tm_ptr->tm_pdu, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, sizeof(tm_write_sock->saddr)); if ((*status == -1) || (*status != *spp_len)) { @@ -737,7 +738,7 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, uint8_t *tm_ptr, uint1 else { printf("crypto_standalone_tm_process - SPP loop error, expected idle packet or frame! tm_ptr = 0x%02x%02x \n", - tm_ptr[0], tm_ptr[1]); + tm_ptr->tm_pdu[0], tm_ptr->tm_pdu[1]); *tm_process_len = 0; } } @@ -752,12 +753,13 @@ void *crypto_standalone_tm_process(void *socks) uint8_t tm_process_in[TM_CADU_SIZE]; // Accounts for ASM automatically based on #def int tm_process_len = 0; uint16_t spp_len = 0; - uint8_t *tm_ptr; + TM_t *tm_ptr = malloc(sizeof(TM_t)); + // AOS_t *aos_ptr; uint16_t tm_out_len = 0; #ifdef CRYPTO_STANDALONE_HANDLE_FRAMING - uint8_t tm_framed[TM_CADU_SIZE]; - uint16_t tm_framed_len = 0; + //uint8_t tm_framed[TM_CADU_SIZE]; + //uint16_t tm_framed_len = 0; #endif int sockaddr_size = sizeof(struct sockaddr_in); @@ -790,16 +792,16 @@ void *crypto_standalone_tm_process(void *socks) // Account for ASM length if (tm_process_in[4] == 0x40) { - status = Crypto_AOS_ProcessSecurity(tm_process_in + 4, (const uint16_t)tm_process_len - 4, &tm_ptr, - &tm_out_len); - if (status != 0) - { - printf("Crypto_AOS_ProcessSecurity Failed with status = %d\n", status); - } + // status = Crypto_AOS_ProcessSecurity(tm_process_in + 4, (const uint16_t)tm_process_len - 4, tm_ptr, + // &tm_out_len); + // if (status != 0) + // { + // printf("Crypto_AOS_ProcessSecurity Failed with status = %d\n", status); + // } } else { - status = Crypto_TM_ProcessSecurity(tm_process_in + 4, (const uint16_t)tm_process_len - 4, &tm_ptr, + status = Crypto_TM_ProcessSecurity(tm_process_in + 4, (const uint16_t)tm_process_len - 4, tm_ptr, &tm_out_len); if (status != 0) { @@ -821,16 +823,17 @@ void *crypto_standalone_tm_process(void *socks) { if (tm_debug == 1) { - if ((tm_ptr[4] == 0x07) && (tm_ptr[5] == 0xFF)) + if ((tm_ptr->tm_header.fhp >> 8 == 0x07) && (((tm_ptr->tm_header.fhp & 0x00FF) == 0xFF) || (tm_ptr->tm_header.fhp & 0x00FF) == 0xFE)) { + printf("OID Frame...\n"); // OID Frame } else { printf("crypto_standalone_tm_process: 1 - status = %d, decrypted[%d]: 0x", status, tm_out_len); - for (int i = 0; i < tm_out_len; i++) + for (int i = 0; i < tm_ptr->tm_pdu_len; i++) { - printf("%02x", tm_ptr[i]); + printf("%02x", tm_ptr->tm_pdu[i]); } printf("\n"); } @@ -839,36 +842,38 @@ void *crypto_standalone_tm_process(void *socks) /* Frame */ #ifdef CRYPTO_STANDALONE_HANDLE_FRAMING #ifdef TM_CADU_HAS_ASM - uint16_t spi = (tm_process_in[10] << 8) | tm_process_in[11]; - crypto_standalone_tm_frame(tm_ptr, tm_out_len, tm_framed, &tm_framed_len, spi); + //uint16_t spi = (tm_ptr->tm_sec_header.spi); + //crypto_standalone_tm_frame(tm_ptr, tm_out_len, tm_framed, &tm_framed_len, spi); #else - uint16_t spi = (tm_process_in[6] << 8) | tm_process_in[7]; - crypto_standalone_tm_frame(tm_process_in, tm_process_len, tm_framed, &tm_framed_len, spi); + //uint16_t spi = (tm_ptr->tm_sec_header.spi); + //crypto_standalone_tm_frame(tm_process_in, tm_process_len, tm_framed, &tm_framed_len, spi); #endif - memcpy(tm_process_in, tm_framed, tm_framed_len); - tm_process_len = tm_framed_len; - tm_framed_len = 0; + // memcpy(tm_process_in, tm_framed, tm_framed_len); + // tm_process_len = tm_framed_len; + // tm_framed_len = 0; if (tm_debug == 1) // Note: Need logic to allow broken packet assembly { printf("crypto_standalone_tm_process: 2 - beginning after first header pointer - deframed[%d]: 0x", - tm_process_len); - for (int i = 0; i < tm_process_len; i++) + tm_ptr->tm_pdu_len); + for (int i = 0; i < tm_ptr->tm_pdu_len; i++) { - printf("%02x", tm_framed[i]); + printf("%02x", tm_ptr->tm_pdu[i]); } printf("\n"); } #endif /* Space Packet Protocol Loop */ - tm_ptr = &tm_process_in[0]; + // memcpy(tm_ptr->tm_pdu, &tm_ptr->tm_pdu[spp_len], spp_len); + tm_process_len = tm_ptr->tm_pdu_len; while (tm_process_len > 5) { // SPP Telemetry OR SPP Idle Packet crypto_standalone_spp_telem_or_idle(&status, tm_ptr, &spp_len, tm_socks, &tm_process_len); - tm_ptr = &tm_ptr[spp_len]; + //tm_ptr->tm_pdu[0] = &tm_ptr->tm_pdu[spp_len]; + memmove(tm_ptr->tm_pdu, tm_ptr->tm_pdu + spp_len, tm_process_len); } } else @@ -877,9 +882,9 @@ void *crypto_standalone_tm_process(void *socks) } /* Reset */ - memset(tm_process_in, 0x00, sizeof(tm_process_in)); - tm_process_len = 0; - memset(tm_ptr, 0x00, sizeof(tm_process_in)); + // memset(tm_process_in, 0x00, sizeof(tm_process_in)); + // tm_process_len = 0; + // memset(tm_ptr, 0x00, sizeof(tm_process_in)); #ifdef CRYPTO_STANDALONE_TM_PROCESS_DEBUG printf("\n"); #endif @@ -888,6 +893,7 @@ void *crypto_standalone_tm_process(void *socks) /* Delay */ usleep(10); } + free(tm_ptr); close(tm_read_sock->sockfd); close(tm_write_sock->sockfd); return tm_read_sock; diff --git a/support/standalone/standalone.h b/support/standalone/standalone.h index c4857b5b..72d8dc44 100644 --- a/support/standalone/standalone.h +++ b/support/standalone/standalone.h @@ -124,9 +124,11 @@ extern "C" int32_t crypto_host_to_ip(const char *hostname, char *ip); int32_t crypto_standalone_udp_init(udp_info_t *sock, int32_t port, uint8_t bind_sock); int32_t crypto_reset(void); + void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t *spp_len, udp_interface_t *tm_socks, + int *tm_process_len); void crypto_standalone_tc_frame(uint8_t *in_data, uint16_t in_length, uint8_t *out_data, uint16_t *out_length); void *crypto_standalone_tc_apply(void *socks); - void crypto_standalone_tm_frame(uint8_t *in_data, uint16_t in_length, uint8_t *out_data, uint16_t *out_length, + void crypto_standalone_tm_frame(TM_t *in_data, uint16_t in_length, uint8_t *out_data, uint16_t *out_length, uint16_t spi); void *crypto_standalone_tm_process(void *socks); void crypto_standalone_cleanup(const int signal); From a0063058a99634c6c322623c7c4dd18c7c8d713b Mon Sep 17 00:00:00 2001 From: Donnie-Ice <77851621+Donnie-Ice@users.noreply.github.com> Date: Fri, 9 Jan 2026 20:22:40 +0000 Subject: [PATCH 2/2] style: auto-format via clang-format --- src/core/crypto_config.c | 2 +- support/standalone/standalone.c | 39 +++++++++++++++++++-------------- support/standalone/standalone.h | 4 ++-- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/core/crypto_config.c b/src/core/crypto_config.c index 129ca013..355856aa 100644 --- a/src/core/crypto_config.c +++ b/src/core/crypto_config.c @@ -104,7 +104,7 @@ int32_t Crypto_SC_Init(void) SecurityAssociation_t *sa_ptr = NULL; if (crypto_config.sa_type == SA_TYPE_MARIADB) { - //mariadb_table_name = MARIADB_TC_TABLE_NAME; + // mariadb_table_name = MARIADB_TC_TABLE_NAME; strncpy(mariadb_table_name, MARIADB_TC_TABLE_NAME, sizeof(mariadb_table_name)); } sa_if->sa_get_from_spi(1, &sa_ptr); diff --git a/support/standalone/standalone.c b/support/standalone/standalone.c index 2803df28..49bc94c3 100644 --- a/support/standalone/standalone.c +++ b/support/standalone/standalone.c @@ -675,7 +675,8 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t { udp_info_t *tm_write_sock = &tm_socks->write; - if (((tm_ptr->tm_pdu[0]) == 0x08) || ((tm_ptr->tm_pdu[0]) == 0x09) || (((tm_ptr->tm_pdu[0]) == 0x07) && ((tm_ptr->tm_pdu[1]) == 0xff)) || + if (((tm_ptr->tm_pdu[0]) == 0x08) || ((tm_ptr->tm_pdu[0]) == 0x09) || + (((tm_ptr->tm_pdu[0]) == 0x07) && ((tm_ptr->tm_pdu[1]) == 0xff)) || ((tm_ptr->tm_pdu[0]) == 0x0F && (tm_ptr->tm_pdu[1]) == 0xFD)) { *spp_len = ((((tm_ptr->tm_pdu[4])) << 8) | (tm_ptr->tm_pdu[5])) + 7; @@ -691,10 +692,11 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t // Send all SPP telemetry packets // 0x09 for HK/Device TLM Packets (Generic Components) // 0x0FFD = CFDP - if ((tm_ptr->tm_pdu[0]) == 0x08 || (tm_ptr->tm_pdu[0]) == 0x09 || ((tm_ptr->tm_pdu[0]) == 0x0f && (tm_ptr->tm_pdu[1]) == 0xfd)) + if ((tm_ptr->tm_pdu[0]) == 0x08 || (tm_ptr->tm_pdu[0]) == 0x09 || + ((tm_ptr->tm_pdu[0]) == 0x0f && (tm_ptr->tm_pdu[1]) == 0xfd)) { - *status = sendto(tm_write_sock->sockfd, tm_ptr->tm_pdu, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, - sizeof(tm_write_sock->saddr)); + *status = sendto(tm_write_sock->sockfd, tm_ptr->tm_pdu, *spp_len, 0, + (struct sockaddr *)&tm_write_sock->saddr, sizeof(tm_write_sock->saddr)); } // Only send idle packets if configured to do so else @@ -703,8 +705,8 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t // Don't forward idle packets *status = *spp_len; #else - *status = sendto(tm_write_sock->sockfd, tm_ptr->tm_pdu, *spp_len, 0, (struct sockaddr *)&tm_write_sock->saddr, - sizeof(tm_write_sock->saddr)); + *status = sendto(tm_write_sock->sockfd, tm_ptr->tm_pdu, *spp_len, 0, + (struct sockaddr *)&tm_write_sock->saddr, sizeof(tm_write_sock->saddr)); #endif } @@ -716,8 +718,10 @@ void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t *tm_process_len -= *spp_len; } - else if (((tm_ptr->tm_pdu[0]) == 0xFF && (tm_ptr->tm_pdu[1]) == 0x48) || ((tm_ptr->tm_pdu[0]) == 0x00 && (tm_ptr->tm_pdu[1]) == 0x00) || - ((tm_ptr->tm_pdu[0]) == 0x02 && (tm_ptr->tm_pdu[1]) == 0x00) || ((tm_ptr->tm_pdu[0]) == 0xFF && (tm_ptr->tm_pdu[1]) == 0xFF)) + else if (((tm_ptr->tm_pdu[0]) == 0xFF && (tm_ptr->tm_pdu[1]) == 0x48) || + ((tm_ptr->tm_pdu[0]) == 0x00 && (tm_ptr->tm_pdu[1]) == 0x00) || + ((tm_ptr->tm_pdu[0]) == 0x02 && (tm_ptr->tm_pdu[1]) == 0x00) || + ((tm_ptr->tm_pdu[0]) == 0xFF && (tm_ptr->tm_pdu[1]) == 0xFF)) { // TODO: Why 0x0200? // Idle Frame @@ -753,13 +757,13 @@ void *crypto_standalone_tm_process(void *socks) uint8_t tm_process_in[TM_CADU_SIZE]; // Accounts for ASM automatically based on #def int tm_process_len = 0; uint16_t spp_len = 0; - TM_t *tm_ptr = malloc(sizeof(TM_t)); + TM_t *tm_ptr = malloc(sizeof(TM_t)); // AOS_t *aos_ptr; uint16_t tm_out_len = 0; #ifdef CRYPTO_STANDALONE_HANDLE_FRAMING - //uint8_t tm_framed[TM_CADU_SIZE]; - //uint16_t tm_framed_len = 0; + // uint8_t tm_framed[TM_CADU_SIZE]; + // uint16_t tm_framed_len = 0; #endif int sockaddr_size = sizeof(struct sockaddr_in); @@ -823,7 +827,8 @@ void *crypto_standalone_tm_process(void *socks) { if (tm_debug == 1) { - if ((tm_ptr->tm_header.fhp >> 8 == 0x07) && (((tm_ptr->tm_header.fhp & 0x00FF) == 0xFF) || (tm_ptr->tm_header.fhp & 0x00FF) == 0xFE)) + if ((tm_ptr->tm_header.fhp >> 8 == 0x07) && + (((tm_ptr->tm_header.fhp & 0x00FF) == 0xFF) || (tm_ptr->tm_header.fhp & 0x00FF) == 0xFE)) { printf("OID Frame...\n"); // OID Frame @@ -842,11 +847,11 @@ void *crypto_standalone_tm_process(void *socks) /* Frame */ #ifdef CRYPTO_STANDALONE_HANDLE_FRAMING #ifdef TM_CADU_HAS_ASM - //uint16_t spi = (tm_ptr->tm_sec_header.spi); - //crypto_standalone_tm_frame(tm_ptr, tm_out_len, tm_framed, &tm_framed_len, spi); + // uint16_t spi = (tm_ptr->tm_sec_header.spi); + // crypto_standalone_tm_frame(tm_ptr, tm_out_len, tm_framed, &tm_framed_len, spi); #else - //uint16_t spi = (tm_ptr->tm_sec_header.spi); - //crypto_standalone_tm_frame(tm_process_in, tm_process_len, tm_framed, &tm_framed_len, spi); + // uint16_t spi = (tm_ptr->tm_sec_header.spi); + // crypto_standalone_tm_frame(tm_process_in, tm_process_len, tm_framed, &tm_framed_len, spi); #endif // memcpy(tm_process_in, tm_framed, tm_framed_len); // tm_process_len = tm_framed_len; @@ -872,7 +877,7 @@ void *crypto_standalone_tm_process(void *socks) { // SPP Telemetry OR SPP Idle Packet crypto_standalone_spp_telem_or_idle(&status, tm_ptr, &spp_len, tm_socks, &tm_process_len); - //tm_ptr->tm_pdu[0] = &tm_ptr->tm_pdu[spp_len]; + // tm_ptr->tm_pdu[0] = &tm_ptr->tm_pdu[spp_len]; memmove(tm_ptr->tm_pdu, tm_ptr->tm_pdu + spp_len, tm_process_len); } } diff --git a/support/standalone/standalone.h b/support/standalone/standalone.h index 72d8dc44..3a0eec4f 100644 --- a/support/standalone/standalone.h +++ b/support/standalone/standalone.h @@ -124,8 +124,8 @@ extern "C" int32_t crypto_host_to_ip(const char *hostname, char *ip); int32_t crypto_standalone_udp_init(udp_info_t *sock, int32_t port, uint8_t bind_sock); int32_t crypto_reset(void); - void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t *spp_len, udp_interface_t *tm_socks, - int *tm_process_len); + void crypto_standalone_spp_telem_or_idle(int32_t *status, TM_t *tm_ptr, uint16_t *spp_len, + udp_interface_t *tm_socks, int *tm_process_len); void crypto_standalone_tc_frame(uint8_t *in_data, uint16_t in_length, uint8_t *out_data, uint16_t *out_length); void *crypto_standalone_tc_apply(void *socks); void crypto_standalone_tm_frame(TM_t *in_data, uint16_t in_length, uint8_t *out_data, uint16_t *out_length,