remove last explicit constant
authorMazet Laurent <laurent.mazet@thalesgroup.com>
Wed, 9 Apr 2025 00:22:55 +0000 (02:22 +0200)
committerMazet Laurent <laurent.mazet@thalesgroup.com>
Wed, 9 Apr 2025 00:22:55 +0000 (02:22 +0200)
12 files changed:
def.h [new file with mode: 0644]
morep_simulator.c
morep_test.c
morep_valid.c
pdu_channel.h
pdu_clear_data.h
pdu_encrypted_data.h
pdu_key.h
pdu_prng_param.h
pdu_raw_data.h
pdu_status.h
simulator.h

diff --git a/def.h b/def.h
new file mode 100644 (file)
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 <laurent.mazet@thalesgroup.com>
+
+  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: */
index b4ff4335a2ba8c85b5f07002b2d2442c8a43568b..ad3b72f816d24dd614a9a4f03d082164684e5695 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#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;
index 84eb0711e41e848d6c8534dab80541b8ea9b1c98..fd785969534354a3f7e50bf8db05cea9aa4b2cd2 100644 (file)
@@ -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"));
index ced7eca99c9d5d7b706c4054c02d83d98367d0b8..c982649d5e2f980d57aa1a142fcf6de885bdd862 100644 (file)
@@ -25,6 +25,7 @@
 #include <string.h>
 #include <unistd.h>
 
+#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);
 
index 1d343563fb9adc9e0b417067bab17d43cdba08f1..43066d90b920d654cb9aff185e2a28eda62e135b 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#include "def.h"
+
 __BEGIN_DECLS
 
 /**
index 906c2788f4e6b809825ddf7e87fecc382ce0b385..af27aef0c455d9f4cf5c6ca75c17930f2ced10c4 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#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;
 
 /**
index a84d7944028c44a23a1f72842c4a92b5a9793e28..5ceb478abf15375bc98a1b15a6c6c286a9ae4617 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#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;
 
 /**
index 5f9e6ef32dcc34953e0c74187aa563cd7eba6614..ec359938aa5ad35709e732ee5bc8b09246303db5 100644 (file)
--- a/pdu_key.h
+++ b/pdu_key.h
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#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;
 
 /**
index eddd3680a8d007d4129968ddcfa2fc0472608836..59744264004d42969421f61295771448109c90e3 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#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;
 
 /**
index 13325ffae9aa57c064736c32e3c64c335973ab29..5187b8af4e845aa662785bea5cbfb0f4815fb242 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#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;
 
 /**
index d9129af53447229b4bdcf70df5c645db0d1d79ea..b13f5d6b4a75074b4bcfb30d6f4679213a01fdc7 100644 (file)
@@ -18,6 +18,8 @@
 #include <stdint.h>
 #include <sys/cdefs.h>
 
+#include "def.h"
+
 __BEGIN_DECLS
 
 /**
index 379c29a2cd8c29d715593ffe96fae160fcd3699c..d5b5b3caad855d332a6bd75c7aa8ff77730ae863 100644 (file)
@@ -1,5 +1,5 @@
 /*
-  File name        : simulator.10
+  File name        : simulator.h
   Projet           : MERLIN
   Date of creation : 2025/04/10
   Version          : 1.0