WIP: Layer 2-Implementierung #6
Loading…
Reference in a new issue
No description provided.
Delete branch "layer2_dev"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In diesem Branch wird das Layer2-Protokoll nach der Spezifikation in
doc/hamnet70.adoc
implementiert.Layer 2-Implementierungto WIP: Layer 2-Implementierung0fc63f5f69
to4bb4017623
@ -0,0 +51,4 @@
uint16_t *tmp = ham64->addr;
memset(ham64->addr, 0, 4*sizeof(uint16_t));
memset(ham64->addr, 0, sizeof(ham64->addr));
Da war ich mir nicht sicher, ob das
sizeof(ham64->addr)
das richtige tut oder doch die Größe von einem Pointer liefert. Aber müsste schon passen. Danke.sizeof
liefert die Größe des jeweiligen Objekts, das funktioniert soweit ich weiß immer. Ausnahmen sind nur so Dinge wiefoo[]
am Ende vom struct (da ist dannsizeof == 0
).@ -0,0 +137,4 @@
"BROADCAST",
"IPV6_MULTICAST",
"IPV4_MULTICAST",
"RESERVED"};
Minor nit: Put
};
on a new line and add a trailing,
after"RESERVED"
?@ -0,0 +173,4 @@
void ham64_format(const ham64_t *ham64, char *out)
{
for(uint8_t i = 0; i < ham64->length; i++) {
sprintf(out + 5 * i, "%04X-", ham64->addr[i]);
Off-by-one overflow (found by fsanitize) if
ham64->length == 4
becausesprintf
NUL-terminates its output but there's not enough space for-
and NUL. Possible fix:@ -0,0 +45,4 @@
memcpy(header->src_addr.addr, encoded + 2, 2 * header->src_addr.length);
memcpy(header->dst_addr.addr, encoded + 2 + 2 * header->src_addr.length, 2 * header->dst_addr.length);
I think the length of
encoded
should be passed as well or invalid src/dst lengths can cause an overread.@ -0,0 +21,4 @@
uint8_t tx_seq_nr; //!< sequence number of this packet
uint8_t rx_seq_nr; //!< sequence number expected next from he other side
Add the maximum value (15) to the comment as the whole
uint_8
cannot be used?@ -0,0 +1,50 @@
#include <stdio.h>
I attached
test_ham64.c
as suggestion to fix the issues I described below.@ -0,0 +7,4 @@
bool test_decode(const char *ref, const ham64_t *ham64)
{
char decoded[13];
decoded[12] = 0;
Only initializing the last byte is problematic because
ham64_decode_callsign
doesn't NUL-terminate with unsupported inputs, causing unitialized stack data to be printed (and with my patch validated) below.@ -0,0 +15,4 @@
ham64_format(ham64, ham64_format_buf);
const char *typestr = ham64_addr_type_to_string(ham64_get_addr_type(ham64));
printf("»%s« → [%u] %s (%s) → [%zd] »%s«\n", ref, ham64->length, ham64_format_buf, typestr, decoded_len, decoded);
These printed results should be verified by the test as well.
@ -0,0 +47,4 @@
test_decode("", &short_1);
test_decode("", &short_last);
test_decode("", &broadcast);
}
The return values are not checked.
ee5c62167a
to153ff61dcd
Looks good now :-)
9b7bae5bd8
toecb8840064
ecb8840064
to017eb221f1
Statusupdate: da 1:1-Kommunikation jetzt ganz gut funktioniert, haben wir diesen Zwischenstand bereits gemerged. Jetzt geht es an das Protokoll für mehrere Nutzer an einem Digipeater.
Ich schließe den PR hier mal. Nachdem das mit dem Layer 2 noch etwas dauert, ist er in dieser Form etwas sinnlos.
Pull request closed