diff --git a/lib/wireshark_connector_impl.cc b/lib/wireshark_connector_impl.cc index 3791ffc..e3a56d1 100644 --- a/lib/wireshark_connector_impl.cc +++ b/lib/wireshark_connector_impl.cc @@ -37,7 +37,7 @@ wireshark_connector_impl::wireshark_connector_impl(LinkType type, bool debug) : message_port_register_in(pmt::mp("in")); - pcap_global *hdr = (pcap_global*)d_msg; + pcap_file_hdr *hdr = (pcap_file_hdr*)d_msg; hdr->magic_number = 0xa1b2c3d4; hdr->version_major = 2; hdr->version_minor = 4; @@ -45,7 +45,7 @@ wireshark_connector_impl::wireshark_connector_impl(LinkType type, bool debug) : hdr->sigfigs = 0; hdr->snaplen = 65535; hdr->network = d_link; - d_msg_len = sizeof(pcap_global); + d_msg_len = sizeof(pcap_file_hdr); } wireshark_connector_impl::~wireshark_connector_impl() { @@ -56,16 +56,48 @@ wireshark_connector_impl::copy_message(const char *buf, int len) { struct timeval t; gettimeofday(&t, NULL); + std::size_t offset = 0; - pcap_pkt hdr; - hdr.ts_sec = t.tv_sec; - hdr.ts_usec = t.tv_usec; - hdr.incl_len = len; - hdr.orig_len = len; + // radiotap header + switch(d_link) { + case WIFI: { + // pcap header + pcap_hdr *hdr = reinterpret_cast(d_msg); + hdr->ts_sec = t.tv_sec; + hdr->ts_usec = t.tv_usec; + hdr->incl_len = len + sizeof(radiotap_hdr); + hdr->orig_len = len + sizeof(radiotap_hdr); + offset += sizeof(struct pcap_hdr); - memcpy(d_msg, &hdr, sizeof(pcap_pkt)); - memcpy(d_msg + sizeof(pcap_pkt), buf, len); - d_msg_len = sizeof(pcap_pkt) + len; + radiotap_hdr *rhdr = reinterpret_cast(d_msg + offset); + rhdr->version = 0; + rhdr->hdr_length = sizeof(radiotap_hdr); + rhdr->bitmap = 0x0000086e; + rhdr->flags = 0; + rhdr->rate = 12; + rhdr->channel = 178; + rhdr->signal = 42; + rhdr->noise = 23; + rhdr->antenna = 1; + offset += sizeof(struct radiotap_hdr); + + break; + } + + case ZIGBEE: { + + pcap_hdr *hdr = reinterpret_cast(d_msg); + hdr->ts_sec = t.tv_sec; + hdr->ts_usec = t.tv_usec; + hdr->incl_len = len; + hdr->orig_len = len; + offset += sizeof(pcap_hdr); + break; + } + } + + memcpy(d_msg + offset, buf, len); + d_msg_len = offset + len; } int diff --git a/lib/wireshark_connector_impl.h b/lib/wireshark_connector_impl.h index d173367..b2b0ce4 100644 --- a/lib/wireshark_connector_impl.h +++ b/lib/wireshark_connector_impl.h @@ -39,7 +39,7 @@ namespace foo { void copy_message(const char *buf, int len); }; - struct pcap_global { + struct pcap_file_hdr { uint32_t magic_number; /* magic number */ uint16_t version_major; /* major version number */ uint16_t version_minor; /* minor version number */ @@ -49,13 +49,25 @@ namespace foo { uint32_t network; /* data link type */ }__attribute__((packed)); - struct pcap_pkt { + struct pcap_hdr { uint32_t ts_sec; /* timestamp seconds */ uint32_t ts_usec; /* timestamp microseconds */ uint32_t incl_len; /* number of octets of packet saved in file */ uint32_t orig_len; /* actual length of packet */ }__attribute__((packed)); + struct radiotap_hdr { + uint16_t version; + uint16_t hdr_length; + uint32_t bitmap; + uint8_t flags; + uint8_t rate; + uint32_t channel; + uint8_t signal; + uint8_t noise; + uint8_t antenna; + }__attribute__((packed)); + } // namespace foo } // namespace gr