From 1697580274765472898e75360e53256fae258565 Mon Sep 17 00:00:00 2001 From: Bastian Bloessl Date: Tue, 16 Jul 2013 12:40:23 +0200 Subject: [PATCH] add ofdm_utils --- lib/CMakeLists.txt | 1 + lib/ofdm_utils.cc | 124 +++++++++++++++++++++++++++++++++++++++++++++ lib/ofdm_utils.h | 88 ++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 lib/ofdm_utils.cc create mode 100644 lib/ofdm_utils.h diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 5fdd743..d909db1 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -28,6 +28,7 @@ list(APPEND gr_ieee802_11_sources ofdm_parse_mac.cc ofdm_sync_long.cc ofdm_sync_short.cc + ofdm_utils.cc ) list(APPEND gr_ieee802_11_libs diff --git a/lib/ofdm_utils.cc b/lib/ofdm_utils.cc new file mode 100644 index 0000000..b21443a --- /dev/null +++ b/lib/ofdm_utils.cc @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2013 Bastian Bloessl + * + * 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 . + */ +#include "ofdm_utils.h" + +#include +#include +#include +#include +#include + + +ofdm_param::ofdm_param(ENCODING e) { + encoding = e; + + switch(e) { + case BPSK_1_2: + n_bpsc = 1; + n_cbps = 48; + n_dbps = 24; + rate_field = 0x0D; // 0b00001101 + break; + + case BPSK_3_4: + n_bpsc = 1; + n_cbps = 48; + n_dbps = 36; + rate_field = 0x0F; // 0b00001111 + break; + + case QPSK_1_2: + n_bpsc = 2; + n_cbps = 96; + n_dbps = 48; + rate_field = 0x05; // 0b00000101 + break; + + case QPSK_3_4: + n_bpsc = 2; + n_cbps = 96; + n_dbps = 72; + rate_field = 0x07; // 0b00000111 + break; + + case QAM16_1_2: + n_bpsc = 4; + n_cbps = 192; + n_dbps = 96; + rate_field = 0x09; // 0b00001001 + break; + + case QAM16_3_4: + n_bpsc = 4; + n_cbps = 192; + n_dbps = 144; + rate_field = 0x0B; // 0b00001011 + break; + + case QAM64_2_3: + n_bpsc = 6; + n_cbps = 288; + n_dbps = 192; + rate_field = 0x01; // 0b00000001 + break; + + case QAM64_3_4: + n_bpsc = 6; + n_cbps = 288; + n_dbps = 216; + rate_field = 0x03; // 0b00000011 + break; + defaut: + assert(false); + break; + } +} + +void +ofdm_param::print_out() { + std::cout << "OFDM Parameters:" << std::endl; + std::cout << "endcoding :" << encoding << std::endl; + std::cout << "rate_field :" << (int)rate_field << std::endl; + std::cout << "n_bpsc :" << n_bpsc << std::endl; + std::cout << "n_cbps :" << n_cbps << std::endl; + std::cout << "n_dbps :" << n_dbps << std::endl; +} + +tx_param::tx_param(ofdm_param &ofdm, int psdu_length) { + + psdu_size = psdu_length; + + // number of symbols (17-11) + n_sym = (int) ceil((16 + 8 * psdu_size + 6) / (double) ofdm.n_dbps); + + // number of bits of the data field (17-12) + n_data = n_sym * ofdm.n_dbps; + + // number of padding bits (17-13) + n_pad = n_data - (16 + 8 * psdu_size + 6); + + n_encoded_bits = n_sym * ofdm.n_cbps; +} +void +tx_param::print_out() { + std::cout << "TX Parameters:" << std::endl; + std::cout << "psdu_size: " << psdu_size << std::endl; + std::cout << "n_sym: " << n_sym << std::endl; + std::cout << "n_data: " << n_data << std::endl; + std::cout << "n_pad: " << n_pad << std::endl; +} + diff --git a/lib/ofdm_utils.h b/lib/ofdm_utils.h new file mode 100644 index 0000000..8748e64 --- /dev/null +++ b/lib/ofdm_utils.h @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2013 Bastian Bloessl + * + * 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 . + */ +#ifndef INCLUDED_IEEE802_11_OFDM_UTILS_H +#define INCLUDED_IEEE802_11_OFDM_UTILS_H + +#include + +/** + * Define structure for the MAC header of a data frame. + * Values as stored as MSB, but standard mandates LSB + * representation. Bit utils functions can help changing + * endiannes + */ +struct MAC_DATAFRAME_HEADER { + char frame_control[2]; //protocol version, type, subtype, to_ds, from_ds, ... + char duration[2]; //duration field + char address1[6]; //address 1 indicating BSSID: 6 bytes MAC address + char address2[6]; //address 2 indicating receiver + char address3[6]; //address 3 indicating sender + char sequence[2]; //sequence number plus fragment number +}; + +enum ENCODING { + BPSK_1_2 = 0, + BPSK_3_4 = 1, + QPSK_1_2 = 2, + QPSK_3_4 = 3, + QAM16_1_2 = 4, + QAM16_3_4 = 5, + QAM64_2_3 = 6, + QAM64_3_4 = 7, +}; + +/** + * OFDM parameters + */ +class ofdm_param { +public: + ofdm_param(ENCODING e); + + // data rate + ENCODING encoding; + // rate field of the SIGNAL header + char rate_field; + // number of coded bits per sub carrier + int n_bpsc; + // number of coded bits per OFDM symbol + int n_cbps; + // number of data bits per OFDM symbol + int n_dbps; + + void print_out(); +}; + +/** + * packet specific parameters + */ +class tx_param { +public: + tx_param(ofdm_param &ofdm, int psdu_length); + // PSDU size in bytes + int psdu_size; + // number of OFDM symbols (17-11) + int n_sym; + // number of data bits in the DATA field, including service and padding (17-12) + int n_data; + // number of padding bits in the DATA field (17-13) + int n_pad; + int n_encoded_bits; + + void print_out(); +}; + +#endif /* INCLUDED_IEEE802_11_OFDM_UTILS_H */