From a9616ce6e36dd52c06bfd600cab7d4ed9c8f479c Mon Sep 17 00:00:00 2001 From: Mazet Laurent Date: Wed, 9 Apr 2025 02:22:55 +0200 Subject: [PATCH] remove last explicit constant --- def.h | 23 +++++++++++++++++++++++ morep_simulator.c | 7 ++++--- morep_test.c | 14 ++++++++------ morep_valid.c | 3 ++- pdu_channel.h | 2 ++ pdu_clear_data.h | 8 +++++--- pdu_encrypted_data.h | 4 +++- pdu_key.h | 4 +++- pdu_prng_param.h | 4 +++- pdu_raw_data.h | 6 ++++-- pdu_status.h | 2 ++ simulator.h | 2 +- 12 files changed, 60 insertions(+), 19 deletions(-) create mode 100644 def.h diff --git a/def.h b/def.h new file mode 100644 index 0000000..bef4dbd --- /dev/null +++ b/def.h @@ -0,0 +1,23 @@ +/* + File name : def.h + Projet : MERLIN + Date of creation : 2025/04/11 + Version : 1.0 + Copyright : Thales SIX + Author : Laurent Mazet + + Description : Global defined constants + + History : + - initial version +*/ + +#ifndef __DEF_H__ +#define __DEF_H__ + +#define MOREP_PAYLOAD 1496 +//#define MOREP_PAYLOAD (1496 * 16 - 1) + +#endif /* __DEF_H__ */ + +/* vim: set ts=4 sw=4 si et: */ diff --git a/morep_simulator.c b/morep_simulator.c index b4ff433..ad3b72f 100644 --- a/morep_simulator.c +++ b/morep_simulator.c @@ -25,6 +25,7 @@ #include #include +#include "def.h" #include "morep.h" #include "parse.h" #include "pdu_channel.h" @@ -476,7 +477,7 @@ int main (int argc, char **argv) } /* send message */ - uint8_t payload[1496] = {0}; + uint8_t payload[MOREP_PAYLOAD] = {0}; switch (pdu) { case channel_e: len = serial_channel (&pdu_channel, payload, sizeof (payload)); @@ -509,7 +510,7 @@ int main (int argc, char **argv) message_t *exp_msg = msg; uint8_t msgtype = 0; - uint8_t payload[1496] = {0}; + uint8_t payload[MOREP_PAYLOAD] = {0}; seqnum = MOREP_Receive (comm->morep, &msgtype, payload, &len); printf("msgtype: %d\n", msgtype); @@ -603,7 +604,7 @@ printf("msgtype: %d %d %d\n", msgtype, msg->msgtype, exp_msg->msgtype); if (log) { fprintf (log, "%c:%s[%s] [SEG=%d MSG=%d LEN=%d PDU=%d] %s", mode ? 'T' : 'R', serv->name, comm->etype, seqnum, msg->msgtype, len, pdu, msg->name); - char buffer[1496 * 3 + 256] = {0}; + char buffer[MOREP_PAYLOAD * 3 + 256] = {0}; switch (pdu) { case nopdu_e: break; diff --git a/morep_test.c b/morep_test.c index 84eb071..fd78596 100644 --- a/morep_test.c +++ b/morep_test.c @@ -26,6 +26,8 @@ #include "morep.h" #include "verbose.h" +#define MOREP_PAYLOAD 1496 + char *progname = NULL; int stop = 0; @@ -69,7 +71,7 @@ int server (char *url) uint8_t rxmsgtype = 0; int rxmsglen = 0; - uint8_t rxbuffer[1496 * 16] = {0}; + uint8_t rxbuffer[MOREP_PAYLOAD * 16] = {0}; int rxseqnum = MOREP_Receive (morep, &rxmsgtype, rxbuffer, &rxmsglen); VERBOSE (morep, INFO, PRINTF ("rx %d bytes (msgid %d) [%d]\n", rxmsglen, rxmsgtype, rxseqnum)); VERBOSE (morep, TRACE, PRINTF ("rx msg: '"); fwrite ((char *)rxbuffer, 1, rxmsglen, stdout); printf ("'\n")); @@ -111,8 +113,8 @@ int clientline (char *url, uint8_t txmsgtype, char *filename) } while (!feof (fid)) { - int txmsglen = 1496; - uint8_t txbuffer[1496] = {0}; + int txmsglen = MOREP_PAYLOAD; + uint8_t txbuffer[MOREP_PAYLOAD] = {0}; int i = 0; do { fread (txbuffer + i, 1, 1, fid); @@ -135,7 +137,7 @@ int clientline (char *url, uint8_t txmsgtype, char *filename) uint8_t rxmsgtype = 0; int rxmsglen = 0; - uint8_t rxbuffer[1496] = {0}; + uint8_t rxbuffer[MOREP_PAYLOAD] = {0}; int rxseqnum = MOREP_Receive (morep, &rxmsgtype, rxbuffer, &rxmsglen); VERBOSE (morep, INFO, PRINTF ("rx %d bytes (msgid %d) [%d]\n", rxmsglen, rxmsgtype, rxseqnum)); VERBOSE (morep, TRACE, PRINTF ("rx msg: '"); fwrite ((char *)rxbuffer, 1, rxmsglen, stdout); printf ("'\n")); @@ -210,7 +212,7 @@ int clientfile (char *url, uint8_t txmsgtype, char *filename) uint8_t *txbuffer = buffer; while (len > 0) { - int txmsglen = 1496 * 16 - 1; + int txmsglen = MOREP_PAYLOAD * 16 - 1; if (len < txmsglen) { txmsglen = len; } @@ -222,7 +224,7 @@ int clientfile (char *url, uint8_t txmsgtype, char *filename) uint8_t rxmsgtype = 0; int rxmsglen = 0; - uint8_t rxbuffer[1496 * 16] = {0}; + uint8_t rxbuffer[MOREP_PAYLOAD * 16] = {0}; int rxseqnum = MOREP_Receive (morep, &rxmsgtype, rxbuffer, &rxmsglen); VERBOSE (morep, INFO, PRINTF ("rx %d bytes (msgid %d) [%d]\n", rxmsglen, rxmsgtype, rxseqnum)); VERBOSE (morep, TRACE, PRINTF ("rx msg: '"); fwrite ((char *)rxbuffer, 1, rxmsglen, stdout); printf ("'\n")); diff --git a/morep_valid.c b/morep_valid.c index ced7eca..c982649 100644 --- a/morep_valid.c +++ b/morep_valid.c @@ -25,6 +25,7 @@ #include #include +#include "def.h" #include "morep.h" #include "parse.h" #include "verbose.h" @@ -316,7 +317,7 @@ int main (int argc, char **argv) } } else { /* receive */ uint8_t rxmsgtype = 0; - uint8_t rxpayload[1496 * 16 - 1] = {0}; + uint8_t rxpayload[MOREP_PAYLOAD] = {0}; int rxlen = -1; int seqnum = MOREP_Receive (comm->morep, &rxmsgtype, rxpayload, &rxlen); diff --git a/pdu_channel.h b/pdu_channel.h index 1d34356..43066d9 100644 --- a/pdu_channel.h +++ b/pdu_channel.h @@ -18,6 +18,8 @@ #include #include +#include "def.h" + __BEGIN_DECLS /** diff --git a/pdu_clear_data.h b/pdu_clear_data.h index 906c278..af27aef 100644 --- a/pdu_clear_data.h +++ b/pdu_clear_data.h @@ -18,6 +18,8 @@ #include #include +#include "def.h" + __BEGIN_DECLS /** @@ -27,10 +29,10 @@ __BEGIN_DECLS */ typedef struct { uint8_t channel_id; /**< channel index */ - int bypass_len; /**< attached bypass message length */ + uint8_t bypass_len; /**< attached bypass message length */ uint8_t bypass[255]; /**< attached bypass message */ - int data_len; /**< data length (must be aligned to 16 bytes) */ - uint8_t data[1472]; /**< data message */ + uint16_t data_len; /**< data length (must be aligned to 16 bytes) */ + uint8_t data[16 * ((MOREP_PAYLOAD - 14) / 16)]; /**< data message */ } CLEAR_DATA_t; /** diff --git a/pdu_encrypted_data.h b/pdu_encrypted_data.h index a84d794..5ceb478 100644 --- a/pdu_encrypted_data.h +++ b/pdu_encrypted_data.h @@ -18,6 +18,8 @@ #include #include +#include "def.h" + __BEGIN_DECLS /** @@ -31,7 +33,7 @@ typedef struct { uint8_t bypass_len; /**< attached bypass message length */ uint8_t bypass[255]; /**< attached bypass message */ uint16_t data_len; /**< data length (must be aligned to 16 bytes) */ - uint8_t data[1472]; /**< data message */ + uint8_t data[16 * ((MOREP_PAYLOAD - 14) / 16)]; /**< data message */ } ENCRYPTED_DATA_t; /** diff --git a/pdu_key.h b/pdu_key.h index 5f9e6ef..ec35993 100644 --- a/pdu_key.h +++ b/pdu_key.h @@ -18,6 +18,8 @@ #include #include +#include "def.h" + __BEGIN_DECLS /** @@ -28,7 +30,7 @@ __BEGIN_DECLS typedef struct { uint8_t key_id; /**< key id */ uint16_t key_len; /**< key length */ - uint8_t key[1495]; /**< raw key */ + uint8_t key[MOREP_PAYLOAD - 1]; /**< raw key */ } KEY_t; /** diff --git a/pdu_prng_param.h b/pdu_prng_param.h index eddd368..5974426 100644 --- a/pdu_prng_param.h +++ b/pdu_prng_param.h @@ -18,6 +18,8 @@ #include #include +#include "def.h" + __BEGIN_DECLS /** @@ -29,7 +31,7 @@ typedef struct { uint8_t prng_id; /**< algorithm index */ uint16_t seq_len; /**< requested PRNG sequence length */ uint8_t seed_len; /**< seed length */ - uint8_t seed[1495]; /**< seed */ + uint8_t seed[MOREP_PAYLOAD - 1]; /**< seed */ } PRNG_PARAM_t; /** diff --git a/pdu_raw_data.h b/pdu_raw_data.h index 13325ff..5187b8a 100644 --- a/pdu_raw_data.h +++ b/pdu_raw_data.h @@ -18,6 +18,8 @@ #include #include +#include "def.h" + __BEGIN_DECLS /** @@ -26,8 +28,8 @@ __BEGIN_DECLS Raw data type */ typedef struct { - int data_len; /**< data length*/ - uint8_t data[1496]; /**< data message */ + uint16_t data_len; /**< data length*/ + uint8_t data[MOREP_PAYLOAD]; /**< data message */ } RAW_DATA_t; /** diff --git a/pdu_status.h b/pdu_status.h index d9129af..b13f5d6 100644 --- a/pdu_status.h +++ b/pdu_status.h @@ -18,6 +18,8 @@ #include #include +#include "def.h" + __BEGIN_DECLS /** diff --git a/simulator.h b/simulator.h index 379c29a..d5b5b3c 100644 --- a/simulator.h +++ b/simulator.h @@ -1,5 +1,5 @@ /* - File name : simulator.10 + File name : simulator.h Projet : MERLIN Date of creation : 2025/04/10 Version : 1.0 -- 2.30.2