cleaner hexa string
authorLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 03:26:12 +0000 (05:26 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 03:26:12 +0000 (05:26 +0200)
morep.c
morep_simulator.c
morep_valid.c
parse.c
script-cross_crypto.eth
script-lo.eth
script-local_crypto.eth
script-prng.eth
script-provisioning.eth
script-rx.eth
script-tx.eth

diff --git a/morep.c b/morep.c
index eb7b1ac5c4de7704649897489f0f808fc830adba..05bbceff15e62791b7c40fd71ac24c4f30c49bf6 100644 (file)
--- a/morep.c
+++ b/morep.c
@@ -372,7 +372,7 @@ int MOREP_Send (int index, uint8_t msgtype, uint8_t *buffer, int len)
         VERBOSE (morep, DEBUG, PRINTF ("flag/frag/length: %d/%d/%d\n", (pklen != len), nfrag, pklen));
         uint16_t msglen = htons (pklen | (nfrag << 11) | ((pklen != len) << 15));
         memcpy (morep->tx_buffer + ETHER_PREAMBLE + 2, (void *) &msglen, 2);
-        VERBOSE (morep, DEBUG, PRINTF ("sent preamble: "); int i; for (i = 0; i < ETHER_PREAMBLE + MOREP_PREAMBLE; i++) printf ("%02x:", morep->tx_buffer[i]); printf ("\n"));
+        VERBOSE (morep, DEBUG, PRINTF ("sent preamble: "); int i; for (i = 0; i < ETHER_PREAMBLE + MOREP_PREAMBLE; i++) printf ("%02x%c", morep->tx_buffer[i], (i == ETHER_PREAMBLE + MOREP_PREAMBLE - 1) ? '\n' : ':'));
 
         memcpy (morep->tx_buffer + ETHER_PREAMBLE + MOREP_PREAMBLE, buffer, pklen);
         int txlen = pklen + ETHER_PREAMBLE + MOREP_PREAMBLE;
@@ -414,7 +414,7 @@ int MOREP_Receive (int index, uint8_t *msgtype, uint8_t *buffer, int *len)
     int flag = 0;
     do {
         rxlen = recvfrom (morep->sock, morep->rx_buffer, ETHER_PREAMBLE + MAX_ETHER_SIZE, 0, NULL, 0);
-        VERBOSE (morep, DEBUG, PRINTF ("rec. preamble: "); int i; for (i = 0; i < ETHER_PREAMBLE + MOREP_PREAMBLE; i++) printf ("%02x:", morep->rx_buffer[i]); printf ("\n"));
+        VERBOSE (morep, DEBUG, PRINTF ("rec. preamble: "); int i; for (i = 0; i < ETHER_PREAMBLE + MOREP_PREAMBLE; i++) printf ("%02x%c", morep->tx_buffer[i], (i == ETHER_PREAMBLE + MOREP_PREAMBLE - 1) ? '\n' : ':'));
 
         /* sequence number */
         int pkgseqnum = morep->rx_buffer[ETHER_PREAMBLE + 1];
index 11cc979a40845dfa255478dc83dd38b30a77388d..b506fd89790d97484fff7dc8369519f80f5a604a 100644 (file)
@@ -604,16 +604,10 @@ int main (int argc, char **argv)
 /* test: morep_simulator.exe -t 2>&1 | grep 'url not specified' */
 /* test: morep_simulator.exe -l - -t lo://00:00:00:00:00:00/0809 -v 4 script-lo.eth */
 /* test: morep_simulator.exe -l script-cross_crypto.log -s CROSS_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-cross_crypto.eth */
-/* test: morep_simulator.exe -l script-cross_crypto.log -s CROSS_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-cross_crypto.eth | grep -v WARNING */
 /* test: morep_simulator.exe -l script-local_crypto.log -s LOCAL_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-local_crypto.eth */
-/* test: morep_simulator.exe -l script-local_crypto.log -s LOCAL_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-local_crypto.eth | grep -v WARNING */
 /* test: morep_simulator.exe -l script-provisioning.log -s PROVISIONING -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-provisioning.eth */
-/* test: morep_simulator.exe -l script-provisioning.log -s PROVISIONING -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-provisioning.eth | grep -v WARNING */
 /* test: morep_simulator.exe -l script-prng.log -s PRNG -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-prng.eth */
-/* test: morep_simulator.exe -l script-prng.log -s PRNG -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-prng.eth | grep -v WARNING */
 /* test: morep_simulator.exe -l script-bypass.log -s BYPASS -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-bypass.eth */
-/* test: morep_simulator.exe -l script-bypass.log -s BYPASS -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-bypass.eth | grep -v WARNING */
 /* test: morep_simulator.exe -l script-control.log -s CONTROL -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-control.eth -v 3 */
-/* test: morep_simulator.exe -l script-control.log -s CONTROL -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-control.eth -v 3 | grep -v WARNING */
 
 /* vim: set ts=4 sw=4 si et: */
index bfd84ad9aca2c3e88afab0b7c6edc9fa0cc9b550..04a0de8c9aae6d1a334d7c0dd2e5be24099aa1e2 100644 (file)
@@ -90,10 +90,9 @@ void print_message (FILE *fd, char *etype, int mode, uint8_t msg, int seqnum, ui
         int i;
         fprintf (fd ? fd : stdout, " PAYLOAD=");
         for (i = 0; i < len; i++) {
-            fprintf (fd, "%02x", payload[i]);
+            fprintf (fd, "%02x%c", payload[i], (i == len - 1) ? '\n' : ':');
         }
     }
-    fprintf (fd ? fd : stdout, "\n");
 }
 
 typedef struct {
diff --git a/parse.c b/parse.c
index 8f6e4439eb9d6435bf2acab45da16dd4fad20c08..5129d9197594bf46e21610413a8e9c67e183483e 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -83,12 +83,12 @@ int parse_array (char *str, uint8_t *buffer, int maxlen)
 
     /* hexa payload: xxxxxx [0-9a-fA-F] */
     else {
-        if (maxlen * 2 < slen) {
-            slen = maxlen * 2;
+        if (maxlen * 3 - 1 < slen) {
+            slen = maxlen * 3 - 1;
         }
-        if (slen % 2 == 0) {
+        if (slen % 3 == 2) {
             VERBOSE (morep, TRACE, PRINTF ("hexa payload: xxxxxx\n"));
-            len = slen / 2;
+            len = slen / 3 + 1;
             if (len > maxlen) {
                 VERBOSE (morep, WARNING, PRINTF ("string too large (%d > %d) for '%s'\n", len, maxlen, str));
                 len = maxlen;
@@ -96,11 +96,11 @@ int parse_array (char *str, uint8_t *buffer, int maxlen)
             for (int i = 0; i < len; i++) {
                 char digit[3] = {0};
                 char *ptr = NULL;
-                digit[0] = str[2 * i];
-                digit[1] = str[2 * i + 1];
+                digit[0] = str[3 * i];
+                digit[1] = str[3 * i + 1];
                 buffer[i] = strtol (digit, &ptr, 16);
-                if ((*ptr != '\0') && (*ptr != ' ') && (*ptr != '\t')) {
-                    VERBOSE (morep, ERROR, PRINTF ("unrecognize hexa-string (%d) '%s'|%s\n", 2 * i, str, ptr));
+                if ((*ptr != ':') && (*ptr != '\0') && (*ptr != ' ') && (*ptr != '\t')) {
+                    VERBOSE (morep, ERROR, PRINTF ("unrecognize hexa-string (%d) '%s'\n", 3 * i, str));
                     break;
                 }
             }
@@ -116,11 +116,11 @@ int parse_array (char *str, uint8_t *buffer, int maxlen)
 
 int snprint_array (char *buffer, int size, char *name, uint8_t *data, int nb)
 {
-    int i;
     int len = snprintf (buffer, size, " %s[%d]=", name, nb);
-    for (i = 0; (i < nb) && (len < size); i++) {
-        len += snprintf (buffer + len, size - len, "%02x", data[i]);
+    for (int i = 0; (i < nb) && (len < size); i++) {
+        len += snprintf (buffer + len, size - len, "%02x:", data[i]);
     }
+    buffer[--len] = '\0';
     return len;
 }
 
index 90edfae73cf85ddedbdc06814b2ddeb839ae3962..67b46ce6903fa35b049756eb8f88ba1f18c04506 100644 (file)
@@ -1,6 +1,6 @@
 # Cross crypto test script
 
-T:CROSS_CRYPTO ENCRYPT_CROSS_ASYNC CHANNELID=2 BYPASSLEN=4 BYPASS=11223344 DATA=@script-local_crypto.eth
+T:CROSS_CRYPTO ENCRYPT_CROSS_ASYNC CHANNELID=2 BYPASSLEN=4 BYPASS=11:22:33:44 DATA=@script-local_crypto.eth
 R:CROSS_CRYPTO ENCRYPT_CROSS_ASYNC
 
 T:CROSS_CRYPTO ENCRYPTED_CROSS_ASYNC CHANNELID=9 BYPASSLEN=1 BYPASS=55 DATA=@script-local_crypto.eth
@@ -9,5 +9,5 @@ R:CROSS_CRYPTO ENCRYPTED_CROSS_ASYNC
 T:CROSS_CRYPTO DECRYPT_CROSS_ASYNC CHANNELID=5 BYPASSLEN=0 DATA=@script-local_crypto.eth
 R:CROSS_CRYPTO DECRYPT_CROSS_ASYNC
 
-T:CROSS_CRYPTO DECRYPTED_CROSS_ASYNC CHANNELID=0 BYPASSLEN=4 BYPASS=11223344 DATA=@script-cross_crypto.eth
+T:CROSS_CRYPTO DECRYPTED_CROSS_ASYNC CHANNELID=0 BYPASSLEN=4 BYPASS=11:22:33:44 DATA=@script-cross_crypto.eth
 R:CROSS_CRYPTO DECRYPTED_CROSS_ASYNC
index 4b574549668ddb56aa457e2680b950fc777e9d58..0daf6bcab34487b2c8aac06d706b034b3d845424 100644 (file)
@@ -5,8 +5,8 @@ R0808 MSG=42 DATA="Hello_world"
 
 SLEEP 1000
 
-T0808 MSG=24 DATA=42796520776f726c64
-R0808 MSG=24 DATA=42796520776f726c64
+T0808 MSG=24 DATA=42:79:65:20:77:6f:72:6c:64
+R0808 MSG=24 DATA=42:79:65:20:77:6f:72:6c:64
 
 T0808 MSG=10 DATA=@script-lo.eth
 R0808 MSG=10 DATA=@script-lo.eth
index cfca6d5e4a2271e2a96196a2d747af5a213b0c38..2b5ce9187c766079806c29be82dd486e1d4d9ac2 100644 (file)
@@ -1,6 +1,6 @@
 # Local crypto test script
 
-T:LOCAL_CRYPTO ENCRYPT_LOCAL_ASYNC CHANNELID=2 BYPASSLEN=4 BYPASS=11223344 DATA=@script-cross_crypto.eth
+T:LOCAL_CRYPTO ENCRYPT_LOCAL_ASYNC CHANNELID=2 BYPASSLEN=3 BYPASS=11:22:33:44 DATA=@script-cross_crypto.eth
 R:LOCAL_CRYPTO ENCRYPT_LOCAL_ASYNC
 
 T:LOCAL_CRYPTO ENCRYPTED_LOCAL_ASYNC CHANNELID=9 BYPASSLEN=0 DATA=@script-local_crypto.eth
@@ -9,5 +9,5 @@ R:LOCAL_CRYPTO ENCRYPTED_LOCAL_ASYNC
 T:LOCAL_CRYPTO DECRYPT_LOCAL_ASYNC CHANNELID=5 BYPASSLEN=0 DATA=@script-local_crypto.eth
 R:LOCAL_CRYPTO DECRYPT_LOCAL_ASYNC
 
-T:LOCAL_CRYPTO DECRYPTED_LOCAL_ASYNC CHANNELID=0 BYPASSLEN=4 BYPASS=11223344 DATA=@script-cross_crypto.eth
+T:LOCAL_CRYPTO DECRYPTED_LOCAL_ASYNC CHANNELID=0 BYPASSLEN=3 BYPASS=11:22:33:44 DATA=@script-cross_crypto.eth
 R:LOCAL_CRYPTO DECRYPTED_LOCAL_ASYNC
index 517cce38db57c2e705d38a62f78b3b865394d85f..2e6a47da29700eba769910c8228f1d0aa6d14971 100644 (file)
@@ -1,6 +1,6 @@
 # PRNG test script
 
-T:PRNG RANDOM_REQ PRNGID=0 SEQLEN=64 SEED=0102030405060708090A0B0C0D0E0F10
+T:PRNG RANDOM_REQ PRNGID=0 SEQLEN=64 SEED=01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F:10
 R:PRNG RANDOM_REQ
 
 T:PRNG RANDOM_RESP DATA=@script-prng.eth
index cbcb1a194e863dd1da26e8f926b95b94418f124a..d078eb31a15726acfb607848c013db811a3bb98f 100644 (file)
@@ -1,6 +1,6 @@
 # Provisioning test script
 
-T:PROVISIONING LOAD_KEY_REQ KEYID=2 KEY=0102030405060708090A0B0C0D0E0F10
+T:PROVISIONING LOAD_KEY_REQ KEYID=2 KEY=01:02:03:04:05:06:07:08:09:0A:0B:0C:0D:0E:0F:10
 R:PROVISIONING LOAD_KEY_REQ
 
 T:PROVISIONING LOAD_KEY_RESP STATUS=0
index 4d2c191a40b8750e76ac7f882beb55efd8bb4d4f..271be015b6f0d4bcc82931cfb288afe61b24c63a 100644 (file)
@@ -5,8 +5,8 @@ T0809 MSG=43 DATA="Bye"
 
 SLEEP 1000
 
-R0808 MSG=24 DATA=42796520776f726c64
-T0809 MSG=25 DATA=48656c6c6f
+R0808 MSG=24 DATA=42:79:65:20:77:6f:72:6c:64
+T0809 MSG=25 DATA=48:65:6c:6c:6f
 
 R0808 MSG=10 DATA=@makefile
 T0809 MSG=11 DATA="OK"
index c09411d2d3394de08cc224ec6f359d7c64052e99..919bb0f1b0f5cc03760506a4872081ab6152807d 100644 (file)
@@ -5,8 +5,8 @@ R0809 MSG=43 DATA="Bye"
 
 SLEEP 1000
 
-T0808 MSG=24 DATA=42796520776f726c64
-R0809 MSG=25 DATA=48656c6c6f
+T0808 MSG=24 DATA=42:79:65:20:77:6f:72:6c:64
+R0809 MSG=25 DATA=48:65:6c:6c:6f
 
 T0808 MSG=10 DATA=@makefile
 R0809 MSG=11 DATA="OK"