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;
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];
/* 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: */
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 {
/* 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;
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;
}
}
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;
}
# 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
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
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
# 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
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
# 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
# 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
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"
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"