wireshark: add support for an IEEE 802.15.4 TAP Header, using a new ZIGBEE_TAP link type

This check for an optional "channel" key in the pmt dict, and adds an
additional TLV to the TAP header.
This commit is contained in:
Mathieu Rene
2024-08-16 21:49:53 -04:00
committed by Bastian Bloessl
parent 7c154d97f7
commit 4190fcd94a
6 changed files with 107 additions and 38 deletions
+53
View File
@@ -16,6 +16,7 @@
*/
#include "wireshark_connector_impl.h"
#include <foo/wireshark_connector.h>
#include <pmt/pmt.h>
#include <gnuradio/io_signature.h>
#include <gnuradio/block_detail.h>
@@ -144,6 +145,58 @@ wireshark_connector_impl::handle_pdu(pmt::pmt_t pdu) {
offset += sizeof(pcap_hdr);
break;
}
case ZIGBEE_TAP:{
const size_t max_extra_size = sizeof(tap_hdr) + sizeof(tap_tlv_fcs) + sizeof(tap_tlv_channel);
size_t extra_size = sizeof(tap_hdr) + sizeof(tap_tlv_fcs);
d_msg = reinterpret_cast<char*>(std::malloc(len + sizeof(pcap_hdr) + max_extra_size));
pcap_hdr *hdr = reinterpret_cast<pcap_hdr*>(d_msg);
hdr->ts_sec = ts_sec;
hdr->ts_usec = ts_usec;
// hdr->incl_len is set at the end of the scope
// hdr->orig_len is set at the end of the scope
offset += sizeof(pcap_hdr);
tap_hdr *tap = reinterpret_cast<tap_hdr*>(d_msg + offset);
tap->version = 0;
tap->reserved = 0;
// tap->length is set at the end of the scope
offset += sizeof(tap_hdr);
tap_tlv_fcs *fcs = reinterpret_cast<tap_tlv_fcs*>(d_msg + offset);
fcs->type = 0; // FCS_TYPE
fcs->length = 1;
fcs->fcs_type = 1; // 16 bit crc
for (int i = 0; i < 3; i++) {
fcs->padding[i] = 0;
}
offset += sizeof(tap_tlv_fcs);
pmt::pmt_t dict = pmt::car(pdu);
if(pmt::dict_has_key(dict, pmt::mp("channel"))) {
pmt::pmt_t s = pmt::dict_ref(dict, pmt::mp("channel"), pmt::PMT_NIL);
if(pmt::is_integer(s)) {
tap_tlv_channel *chan = reinterpret_cast<tap_tlv_channel*>(d_msg + offset);
chan->type = 3; // CHANNEL_ASSIGNMENT
chan->length = 3;
chan->channel_number = (uint16_t)pmt::to_long(s);
chan->channel_page = 0;
chan->padding = 0;
offset += sizeof(tap_tlv_channel);
extra_size += sizeof(tap_tlv_channel);
}
}
tap->length = extra_size;
hdr->incl_len = len + extra_size;
hdr->orig_len = len + extra_size;
break;
}
}
memcpy(d_msg + offset, buf, len);
+29
View File
@@ -75,6 +75,35 @@ namespace foo {
};
#pragma pack(pop)
#pragma pack(push, 1)
// An 802.15.4 TAP header as defined in https://gitlab.com/exegin/ieee802-15-4-tap/
struct tap_hdr {
uint8_t version;
uint8_t reserved;
uint16_t length;
};
#pragma pack(pop)
#pragma pack(push, 1)
struct tap_tlv_fcs {
uint16_t type; // FCS_TYPE = 0
uint16_t length; // 1
uint8_t fcs_type; // 0 = None, 1 = 16-bit CRC, 2 = 32-bit CRC
uint8_t padding[3]; // Should be 0 padded
};
#pragma pack(pop)
#pragma pack(push, 1)
struct tap_tlv_channel {
uint16_t type; // CHANNEL_ASSIGNMENT = 3
uint16_t length; // 3
uint16_t channel_number;
uint8_t channel_page;
uint8_t padding; // Should be 0 padded
};
#pragma pack(pop)
} // namespace foo
} // namespace gr