define mac_header in utils

This commit is contained in:
Bastian Bloessl
2013-10-15 19:46:59 +02:00
parent 0bd43f83fe
commit e030e0e069
5 changed files with 38 additions and 76 deletions
+2 -3
View File
@@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ether_encap_impl.h"
#include "ofdm_parse_mac_impl.h"
#include "utils.h"
#include <gnuradio/io_signature.h>
@@ -48,12 +47,12 @@ ether_encap_impl::from_wifi(pmt::pmt_t msg) {
int data_len = pmt::blob_length(msg);
const mac_header *mhdr = reinterpret_cast<const mac_header*>(pmt::blob_data(msg));
if(d_last_seq == mhdr->seq_control) {
if(d_last_seq == mhdr->seq_nr) {
dout << "Ether Encap: frame already seen -- skipping" << std::endl;
return;
}
d_last_seq = mhdr->seq_control;
d_last_seq = mhdr->seq_nr;
if(data_len < 33) {
+27 -33
View File
@@ -100,46 +100,39 @@ void app_in (pmt::pmt_t msg) {
void generate_mac_data_frame(const char *msdu, int msdu_size, char **psdu, int *psdu_size) {
//mac frame
MAC_DATAFRAME_HEADER header;
//frame check sequence
unsigned int fcs;
// mac header
mac_header header;
header.frame_control = 0x0008;
header.duration = 0x002e;
// TODO: change this back to 0x08
header.frame_control[0] = 0x08;//0x20; //00000100 00100000 indicate DATA frame (LOL, not), to_ds, from_ds, more frag, retry
header.frame_control[1] = 0x00;//0x40; //all other flags, unutilized //00000010 01000000
header.addr1[0] = 0x30;
header.addr1[1] = 0x14;
header.addr1[2] = 0x4a;
header.addr1[3] = 0xe6;
header.addr1[4] = 0x46;
header.addr1[5] = 0xe4;
header.duration[0] = 0x00; //TODO: set accordingly to payload
header.duration[1] = 0x2e; //0x74; //2e = 00101110 -> 01110100 -> 74
header.addr2[0] = 0x12;
header.addr2[1] = 0x34;
header.addr2[2] = 0x56;
header.addr2[3] = 0x78;
header.addr2[4] = 0x90;
header.addr2[5] = 0xab;
header.address1[0] = 0x30;
header.address1[1] = 0x14;
header.address1[2] = 0x4a;
header.address1[3] = 0xe6;
header.address1[4] = 0x46;
header.address1[5] = 0xe4;
header.addr3[0] = 0x42;
header.addr3[1] = 0x42;
header.addr3[2] = 0x42;
header.addr3[3] = 0x42;
header.addr3[4] = 0x42;
header.addr3[5] = 0x42;
header.address2[0] = 0x12;
header.address2[1] = 0x34;
header.address2[2] = 0x56;
header.address2[3] = 0x78;
header.address2[4] = 0x90;
header.address2[5] = 0xab;
header.address3[0] = 0x42;
header.address3[1] = 0x42;
header.address3[2] = 0x42;
header.address3[3] = 0x42;
header.address3[4] = 0x42;
header.address3[5] = 0x42;
header.sequence = 0;
header.seq_nr = 0;
for (int i = 0; i < 12; i++) {
if(d_seq_nr & (1 << i)) {
header.sequence |= (1 << (i + 4));
header.seq_nr |= (1 << (i + 4));
}
}
header.sequence = htole16(header.sequence);
header.seq_nr = htole16(header.seq_nr);
d_seq_nr++;
//header size is 24, plus 4 for FCS means 28 bytes
@@ -153,7 +146,8 @@ void generate_mac_data_frame(const char *msdu, int msdu_size, char **psdu, int *
//compute and store fcs
boost::crc_32_type result;
result.process_bytes(*psdu, msdu_size + 24);
fcs = result.checksum();
unsigned int fcs = result.checksum();
memcpy(*psdu + msdu_size + 24, &fcs, sizeof(unsigned int));
}
+2 -3
View File
@@ -15,7 +15,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <ieee802-11/ofdm_parse_mac.h>
#include "ofdm_parse_mac_impl.h"
#include "utils.h"
#include <gnuradio/io_signature.h>
@@ -179,7 +178,7 @@ void parse_management(char *buf, int length) {
}
dout << std::endl;
dout << "seq nr: " << int(h->seq_control >> 4) << std::endl;
dout << "seq nr: " << int(h->seq_nr >> 4) << std::endl;
dout << "mac 1: ";
print_mac_address(h->addr1, true);
dout << "mac 2: ";
@@ -252,7 +251,7 @@ void parse_data(char *buf, int length) {
}
dout << std::endl;
dout << "seq nr: " << int(h->seq_control >> 4) << std::endl;
dout << "seq nr: " << int(h->seq_nr >> 4) << std::endl;
dout << "mac 1: ";
print_mac_address(h->addr1, true);
dout << "mac 2: ";
-30
View File
@@ -1,30 +0,0 @@
/*
* Copyright (C) 2013 Bastian Bloessl <bloessl@ccs-labs.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef INCLUDED_IEEE802_11_OFDM_PARSE_MAC_IMPL_H
#define INCLUDED_IEEE802_11_OFDM_PARSE_MAC_IMPL_H
struct mac_header {
uint16_t frame_control;
uint16_t duration;
uint8_t addr1[6];
uint8_t addr2[6];
uint8_t addr3[6];
uint16_t seq_control;
}__attribute__((packed));
#endif /* INCLUDED_IEEE802_11_OFDM_PARSE_MAC_IMPL_H */
+7 -7
View File
@@ -36,14 +36,14 @@ extern const std::complex<double> QPSK_D[4];
extern const std::complex<double> QAM16_D[16];
extern const std::complex<double> QAM64_D[64];
struct MAC_DATAFRAME_HEADER {
struct mac_header {
//protocol version, type, subtype, to_ds, from_ds, ...
char frame_control[2];
char duration[2];
char address1[6];
char address2[6];
char address3[6];
uint16_t sequence;
uint16_t frame_control;
uint16_t duration;
uint8_t addr1[6];
uint8_t addr2[6];
uint8_t addr3[6];
uint16_t seq_nr;
}__attribute__((packed));
/**