packet_structs: add function to dump a packet header to the log
This commit is contained in:
parent
3068db1d50
commit
12e727be00
|
@ -1,6 +1,9 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#define LOGGER_MODULE_NAME "l2ps"
|
||||||
|
#include "logger.h"
|
||||||
|
|
||||||
#include "packet_structs.h"
|
#include "packet_structs.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,3 +70,49 @@ bool layer2_decode_packet_header(const uint8_t *encoded, size_t encoded_len, lay
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const char* msg_type_to_string(layer2_message_type_t type)
|
||||||
|
{
|
||||||
|
switch(type) {
|
||||||
|
case L2_MSG_TYPE_CONNECTIONLESS: return "Connectionless";
|
||||||
|
case L2_MSG_TYPE_DATA: return "Data";
|
||||||
|
case L2_MSG_TYPE_CONN_MGMT: return "Connection Management";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void layer2_dump_packet_header(int level, const layer2_packet_header_t *header)
|
||||||
|
{
|
||||||
|
LOG(level, "Packet header dump:");
|
||||||
|
LOG(level, " Packet type: %s", msg_type_to_string(header->msg_type));
|
||||||
|
LOG(level, " TX Request: %s", header->tx_request ? "true" : "false");
|
||||||
|
LOG(level, " RX Seq. Nr: %2u", header->rx_seq_nr);
|
||||||
|
LOG(level, " TX Seq. Nr: %2u", header->tx_seq_nr);
|
||||||
|
|
||||||
|
ham64_addr_type_t addr_type;
|
||||||
|
char addr_buf[HAM64_FMT_MAX_LEN];
|
||||||
|
|
||||||
|
addr_type = ham64_get_addr_type(&header->src_addr);
|
||||||
|
ham64_format(&header->src_addr, addr_buf);
|
||||||
|
|
||||||
|
if(addr_type == HAM64_ADDR_TYPE_CALLSIGN) {
|
||||||
|
char callsign[13];
|
||||||
|
ham64_decode_callsign(&header->src_addr, callsign);
|
||||||
|
LOG(level, " Source Address: %s [%s] -> %s", addr_buf, ham64_addr_type_to_string(addr_type), callsign);
|
||||||
|
} else {
|
||||||
|
LOG(level, " Source Address: %s [%s]", addr_buf, ham64_addr_type_to_string(addr_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
addr_type = ham64_get_addr_type(&header->dst_addr);
|
||||||
|
ham64_format(&header->dst_addr, addr_buf);
|
||||||
|
|
||||||
|
if(addr_type == HAM64_ADDR_TYPE_CALLSIGN) {
|
||||||
|
char callsign[13];
|
||||||
|
ham64_decode_callsign(&header->dst_addr, callsign);
|
||||||
|
LOG(level, " Dest. Address: %s [%s] -> %s", addr_buf, ham64_addr_type_to_string(addr_type), callsign);
|
||||||
|
} else {
|
||||||
|
LOG(level, " Dest. Address: %s [%s]", addr_buf, ham64_addr_type_to_string(addr_type));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -61,6 +61,12 @@ size_t layer2_get_encoded_header_size(const layer2_packet_header_t *header);
|
||||||
*/
|
*/
|
||||||
bool layer2_decode_packet_header(const uint8_t *encoded, size_t encoded_len, layer2_packet_header_t *header);
|
bool layer2_decode_packet_header(const uint8_t *encoded, size_t encoded_len, layer2_packet_header_t *header);
|
||||||
|
|
||||||
|
/*!\brief Dump a layer 2 packet header structure.
|
||||||
|
* \param level Log level (e.g. LVL_INFO; see the logger module).
|
||||||
|
* \param header The header structure to dump.
|
||||||
|
*/
|
||||||
|
void layer2_dump_packet_header(int level, const layer2_packet_header_t *header);
|
||||||
|
|
||||||
/* Data Packet Structs */
|
/* Data Packet Structs */
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
Loading…
Reference in a new issue