clang format, similar to GNU Radio

This commit is contained in:
Bastian Bloessl
2021-07-17 10:07:21 +02:00
parent 5f7e102e3d
commit a2491b5474
50 changed files with 3331 additions and 3059 deletions
+104
View File
@@ -0,0 +1,104 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterClass: true
AfterControlStatement: false
AfterEnum: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 90
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^"(gnuradio)/'
Priority: 1
- Regex: '^<(gnuradio)/'
Priority: 2
- Regex: '^<(boost)/'
Priority: 98
- Regex: '^<[a-z]*>$'
Priority: 99
- Regex: '^".*"$'
Priority: 0
- Regex: '.*'
Priority: 10
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
+1 -1
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_CHUNKS_TO_SYMBOLS_H #ifndef INCLUDED_IEEE802_11_CHUNKS_TO_SYMBOLS_H
#define INCLUDED_IEEE802_11_CHUNKS_TO_SYMBOLS_H #define INCLUDED_IEEE802_11_CHUNKS_TO_SYMBOLS_H
#include <ieee802_11/api.h>
#include <gnuradio/tagged_stream_block.h> #include <gnuradio/tagged_stream_block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
+1 -2
View File
@@ -18,8 +18,8 @@
#ifndef INCLUDED_IEEE802_11_CONSTELLATIONS_H #ifndef INCLUDED_IEEE802_11_CONSTELLATIONS_H
#define INCLUDED_IEEE802_11_CONSTELLATIONS_H #define INCLUDED_IEEE802_11_CONSTELLATIONS_H
#include <ieee802_11/api.h>
#include <gnuradio/digital/constellation.h> #include <gnuradio/digital/constellation.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -68,4 +68,3 @@ protected:
} // namespace gr } // namespace gr
#endif /* INCLUDED_IEEE802_11_CONSTELLATIONS_H */ #endif /* INCLUDED_IEEE802_11_CONSTELLATIONS_H */
+1 -5
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_DECODE_MAC_H #ifndef INCLUDED_IEEE802_11_DECODE_MAC_H
#define INCLUDED_IEEE802_11_DECODE_MAC_H #define INCLUDED_IEEE802_11_DECODE_MAC_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -26,15 +26,11 @@ namespace ieee802_11 {
class IEEE802_11_API decode_mac : virtual public block class IEEE802_11_API decode_mac : virtual public block
{ {
public: public:
typedef boost::shared_ptr<decode_mac> sptr; typedef boost::shared_ptr<decode_mac> sptr;
static sptr make(bool log = false, bool debug = false); static sptr make(bool log = false, bool debug = false);
}; };
} // namespace ieee802_11 } // namespace ieee802_11
} // namespace gr } // namespace gr
#endif /* INCLUDED_IEEE802_11_DECODE_MAC_H */ #endif /* INCLUDED_IEEE802_11_DECODE_MAC_H */
+1 -3
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_ETHER_ENCAP_H #ifndef INCLUDED_IEEE802_11_ETHER_ENCAP_H
#define INCLUDED_IEEE802_11_ETHER_ENCAP_H #define INCLUDED_IEEE802_11_ETHER_ENCAP_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -26,10 +26,8 @@ namespace ieee802_11 {
class IEEE802_11_API ether_encap : virtual public block class IEEE802_11_API ether_encap : virtual public block
{ {
public: public:
typedef boost::shared_ptr<ether_encap> sptr; typedef boost::shared_ptr<ether_encap> sptr;
static sptr make(bool debug); static sptr make(bool debug);
}; };
} // namespace ieee802_11 } // namespace ieee802_11
+3 -2
View File
@@ -21,13 +21,14 @@
#ifndef INCLUDED_IEEE802_11_EXTRACT_CSI_H #ifndef INCLUDED_IEEE802_11_EXTRACT_CSI_H
#define INCLUDED_IEEE802_11_EXTRACT_CSI_H #define INCLUDED_IEEE802_11_EXTRACT_CSI_H
#include <ieee802_11/api.h>
#include <gnuradio/sync_block.h> #include <gnuradio/sync_block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
class IEEE802_11_API extract_csi : virtual public gr::sync_block { class IEEE802_11_API extract_csi : virtual public gr::sync_block
{
public: public:
typedef boost::shared_ptr<extract_csi> sptr; typedef boost::shared_ptr<extract_csi> sptr;
static sptr make(); static sptr make();
+2 -3
View File
@@ -20,8 +20,8 @@
#ifndef INCLUDED_IEEE802_11_FRAME_EQUALIZER_H #ifndef INCLUDED_IEEE802_11_FRAME_EQUALIZER_H
#define INCLUDED_IEEE802_11_FRAME_EQUALIZER_H #define INCLUDED_IEEE802_11_FRAME_EQUALIZER_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
enum Equalizer { enum Equalizer {
LS = 0, LS = 0,
@@ -38,8 +38,7 @@ class IEEE802_11_API frame_equalizer : virtual public gr::block
public: public:
typedef boost::shared_ptr<frame_equalizer> sptr; typedef boost::shared_ptr<frame_equalizer> sptr;
static sptr make(Equalizer algo, double freq, double bw, static sptr make(Equalizer algo, double freq, double bw, bool log, bool debug);
bool log, bool debug);
virtual void set_algorithm(Equalizer algo) = 0; virtual void set_algorithm(Equalizer algo) = 0;
virtual void set_bandwidth(double bw) = 0; virtual void set_bandwidth(double bw) = 0;
virtual void set_frequency(double freq) = 0; virtual void set_frequency(double freq) = 0;
+1 -2
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_MAC_H #ifndef INCLUDED_IEEE802_11_MAC_H
#define INCLUDED_IEEE802_11_MAC_H #define INCLUDED_IEEE802_11_MAC_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -26,7 +26,6 @@ namespace ieee802_11 {
class IEEE802_11_API mac : virtual public block class IEEE802_11_API mac : virtual public block
{ {
public: public:
typedef boost::shared_ptr<mac> sptr; typedef boost::shared_ptr<mac> sptr;
static sptr make(std::vector<uint8_t> src_mac, static sptr make(std::vector<uint8_t> src_mac,
std::vector<uint8_t> dst_mac, std::vector<uint8_t> dst_mac,
+1 -2
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_MAPPER_H #ifndef INCLUDED_IEEE802_11_MAPPER_H
#define INCLUDED_IEEE802_11_MAPPER_H #define INCLUDED_IEEE802_11_MAPPER_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
enum Encoding { enum Encoding {
BPSK_1_2 = 0, BPSK_1_2 = 0,
@@ -37,7 +37,6 @@ namespace ieee802_11 {
class IEEE802_11_API mapper : virtual public block class IEEE802_11_API mapper : virtual public block
{ {
public: public:
typedef boost::shared_ptr<mapper> sptr; typedef boost::shared_ptr<mapper> sptr;
static sptr make(Encoding mcs, bool debug = false); static sptr make(Encoding mcs, bool debug = false);
virtual void set_encoding(Encoding mcs) = 0; virtual void set_encoding(Encoding mcs) = 0;
+1 -3
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_PARSE_MAC_H #ifndef INCLUDED_IEEE802_11_PARSE_MAC_H
#define INCLUDED_IEEE802_11_PARSE_MAC_H #define INCLUDED_IEEE802_11_PARSE_MAC_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -26,10 +26,8 @@ namespace ieee802_11 {
class IEEE802_11_API parse_mac : virtual public block class IEEE802_11_API parse_mac : virtual public block
{ {
public: public:
typedef boost::shared_ptr<parse_mac> sptr; typedef boost::shared_ptr<parse_mac> sptr;
static sptr make(bool log = false, bool debug = false); static sptr make(bool log = false, bool debug = false);
}; };
} // namespace ieee802_11 } // namespace ieee802_11
+1 -2
View File
@@ -18,8 +18,8 @@
#ifndef INCLUDED_IEEE802_11_SIGNAL_FIELD_H #ifndef INCLUDED_IEEE802_11_SIGNAL_FIELD_H
#define INCLUDED_IEEE802_11_SIGNAL_FIELD_H #define INCLUDED_IEEE802_11_SIGNAL_FIELD_H
#include <ieee802_11/api.h>
#include <gnuradio/digital/packet_header_default.h> #include <gnuradio/digital/packet_header_default.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -38,4 +38,3 @@ protected:
} // namespace gr } // namespace gr
#endif /* INCLUDED_IEEE802_11_SIGNAL_FIELD_H */ #endif /* INCLUDED_IEEE802_11_SIGNAL_FIELD_H */
+2 -5
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_SYNC_LONG_H #ifndef INCLUDED_IEEE802_11_SYNC_LONG_H
#define INCLUDED_IEEE802_11_SYNC_LONG_H #define INCLUDED_IEEE802_11_SYNC_LONG_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -26,11 +26,8 @@ namespace ieee802_11 {
class IEEE802_11_API sync_long : virtual public block class IEEE802_11_API sync_long : virtual public block
{ {
public: public:
typedef boost::shared_ptr<sync_long> sptr; typedef boost::shared_ptr<sync_long> sptr;
static sptr make(unsigned int sync_length, static sptr make(unsigned int sync_length, bool log = false, bool debug = false);
bool log = false, bool debug = false);
}; };
} // namespace ieee802_11 } // namespace ieee802_11
+5 -4
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_SYNC_SHORT_H #ifndef INCLUDED_IEEE802_11_SYNC_SHORT_H
#define INCLUDED_IEEE802_11_SYNC_SHORT_H #define INCLUDED_IEEE802_11_SYNC_SHORT_H
#include <ieee802_11/api.h>
#include <gnuradio/block.h> #include <gnuradio/block.h>
#include <ieee802_11/api.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -26,10 +26,11 @@ namespace ieee802_11 {
class IEEE802_11_API sync_short : virtual public block class IEEE802_11_API sync_short : virtual public block
{ {
public: public:
typedef boost::shared_ptr<sync_short> sptr; typedef boost::shared_ptr<sync_short> sptr;
static sptr make(double threshold, unsigned int min_plateau, bool log = false, bool debug = false); static sptr make(double threshold,
unsigned int min_plateau,
bool log = false,
bool debug = false);
}; };
} // namespace ieee802_11 } // namespace ieee802_11
+11 -11
View File
@@ -22,16 +22,17 @@
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
chunks_to_symbols::sptr chunks_to_symbols::sptr chunks_to_symbols::make()
chunks_to_symbols::make()
{ {
return gnuradio::get_initial_sptr(new chunks_to_symbols_impl()); return gnuradio::get_initial_sptr(new chunks_to_symbols_impl());
} }
chunks_to_symbols_impl::chunks_to_symbols_impl() : chunks_to_symbols_impl::chunks_to_symbols_impl()
tagged_stream_block("chunks_to_symbols", : tagged_stream_block("chunks_to_symbols",
io_signature::make(1, 1, sizeof(char)), io_signature::make(1, 1, sizeof(char)),
io_signature::make(1, 1, sizeof(gr_complex)), "packet_len") { io_signature::make(1, 1, sizeof(gr_complex)),
"packet_len")
{
d_bpsk = constellation_bpsk::make(); d_bpsk = constellation_bpsk::make();
d_qpsk = constellation_qpsk::make(); d_qpsk = constellation_qpsk::make();
@@ -44,19 +45,18 @@ chunks_to_symbols_impl::chunks_to_symbols_impl() :
chunks_to_symbols_impl::~chunks_to_symbols_impl() {} chunks_to_symbols_impl::~chunks_to_symbols_impl() {}
int int chunks_to_symbols_impl::work(int noutput_items,
chunks_to_symbols_impl::work(int noutput_items,
gr_vector_int& ninput_items, gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items, gr_vector_const_void_star& input_items,
gr_vector_void_star &output_items) { gr_vector_void_star& output_items)
{
const unsigned char* in = (unsigned char*)input_items[0]; const unsigned char* in = (unsigned char*)input_items[0];
gr_complex* out = (gr_complex*)output_items[0]; gr_complex* out = (gr_complex*)output_items[0];
std::vector<tag_t> tags; std::vector<tag_t> tags;
get_tags_in_range(tags, 0, nitems_read(0), get_tags_in_range(
nitems_read(0) + ninput_items[0], tags, 0, nitems_read(0), nitems_read(0) + ninput_items[0], pmt::mp("encoding"));
pmt::mp("encoding"));
if (tags.size() != 1) { if (tags.size() != 1) {
throw std::runtime_error("no encoding in input stream"); throw std::runtime_error("no encoding in input stream");
} }
+25 -27
View File
@@ -18,14 +18,15 @@
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
constellation_bpsk::sptr constellation_bpsk::sptr constellation_bpsk::make()
constellation_bpsk::make() { {
return constellation_bpsk::sptr(new constellation_bpsk_impl()); return constellation_bpsk::sptr(new constellation_bpsk_impl());
} }
constellation_bpsk::constellation_bpsk() {} constellation_bpsk::constellation_bpsk() {}
constellation_bpsk_impl::constellation_bpsk_impl() { constellation_bpsk_impl::constellation_bpsk_impl()
{
d_constellation.resize(2); d_constellation.resize(2);
d_constellation[0] = gr_complex(-1, 0); d_constellation[0] = gr_complex(-1, 0);
d_constellation[1] = gr_complex(1, 0); d_constellation[1] = gr_complex(1, 0);
@@ -34,25 +35,25 @@ constellation_bpsk_impl::constellation_bpsk_impl() {
calc_arity(); calc_arity();
} }
constellation_bpsk_impl::~constellation_bpsk_impl() { constellation_bpsk_impl::~constellation_bpsk_impl() {}
}
unsigned int unsigned int constellation_bpsk_impl::decision_maker(const gr_complex* sample)
constellation_bpsk_impl::decision_maker(const gr_complex *sample) { {
return (real(*sample) > 0); return (real(*sample) > 0);
} }
/**********************************************************/ /**********************************************************/
constellation_qpsk::sptr constellation_qpsk::sptr constellation_qpsk::make()
constellation_qpsk::make() { {
return constellation_qpsk::sptr(new constellation_qpsk_impl()); return constellation_qpsk::sptr(new constellation_qpsk_impl());
} }
constellation_qpsk::constellation_qpsk() {} constellation_qpsk::constellation_qpsk() {}
constellation_qpsk_impl::constellation_qpsk_impl() { constellation_qpsk_impl::constellation_qpsk_impl()
{
const float level = sqrt(float(0.5)); const float level = sqrt(float(0.5));
d_constellation.resize(4); d_constellation.resize(4);
// Gray-coded // Gray-coded
@@ -66,19 +67,18 @@ constellation_qpsk_impl::constellation_qpsk_impl() {
calc_arity(); calc_arity();
} }
constellation_qpsk_impl::~constellation_qpsk_impl() { constellation_qpsk_impl::~constellation_qpsk_impl() {}
}
unsigned int unsigned int constellation_qpsk_impl::decision_maker(const gr_complex* sample)
constellation_qpsk_impl::decision_maker(const gr_complex *sample) { {
return 2 * (imag(*sample) > 0) + (real(*sample) > 0); return 2 * (imag(*sample) > 0) + (real(*sample) > 0);
} }
/**********************************************************/ /**********************************************************/
constellation_16qam::sptr constellation_16qam::sptr constellation_16qam::make()
constellation_16qam::make() { {
return constellation_16qam::sptr(new constellation_16qam_impl()); return constellation_16qam::sptr(new constellation_16qam_impl());
} }
@@ -111,11 +111,9 @@ constellation_16qam_impl::constellation_16qam_impl()
calc_arity(); calc_arity();
} }
constellation_16qam_impl::~constellation_16qam_impl() { constellation_16qam_impl::~constellation_16qam_impl() {}
}
unsigned int unsigned int constellation_16qam_impl::decision_maker(const gr_complex* sample)
constellation_16qam_impl::decision_maker(const gr_complex *sample)
{ {
unsigned int ret = 0; unsigned int ret = 0;
const float level = sqrt(float(0.1)); const float level = sqrt(float(0.1));
@@ -133,14 +131,15 @@ constellation_16qam_impl::decision_maker(const gr_complex *sample)
/**********************************************************/ /**********************************************************/
constellation_64qam::sptr constellation_64qam::sptr constellation_64qam::make()
constellation_64qam::make() { {
return constellation_64qam::sptr(new constellation_64qam_impl()); return constellation_64qam::sptr(new constellation_64qam_impl());
} }
constellation_64qam::constellation_64qam() {} constellation_64qam::constellation_64qam() {}
constellation_64qam_impl::constellation_64qam_impl() { constellation_64qam_impl::constellation_64qam_impl()
{
const float level = sqrt(float(1 / 42.0)); const float level = sqrt(float(1 / 42.0));
d_constellation.resize(64); d_constellation.resize(64);
@@ -214,11 +213,10 @@ constellation_64qam_impl::constellation_64qam_impl() {
calc_arity(); calc_arity();
} }
constellation_64qam_impl::~constellation_64qam_impl() { constellation_64qam_impl::~constellation_64qam_impl() {}
}
unsigned int unsigned int constellation_64qam_impl::decision_maker(const gr_complex* sample)
constellation_64qam_impl::decision_maker(const gr_complex *sample) { {
unsigned int ret = 0; unsigned int ret = 0;
const float level = sqrt(float(1 / 42.0)); const float level = sqrt(float(1 / 42.0));
float re = sample->real(); float re = sample->real();
-3
View File
@@ -42,7 +42,6 @@ public:
}; };
class constellation_16qam_impl : public constellation_16qam class constellation_16qam_impl : public constellation_16qam
{ {
public: public:
@@ -53,8 +52,6 @@ public:
}; };
class constellation_64qam_impl : public constellation_64qam class constellation_64qam_impl : public constellation_64qam
{ {
public: public:
+54 -33
View File
@@ -19,18 +19,19 @@
#include "utils.h" #include "utils.h"
#include "viterbi_decoder/viterbi_decoder.h" #include "viterbi_decoder/viterbi_decoder.h"
#include <boost/crc.hpp>
#include <gnuradio/io_signature.h> #include <gnuradio/io_signature.h>
#include <boost/crc.hpp>
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
#define LINKTYPE_IEEE802_11 105 /* http://www.tcpdump.org/linktypes.html */ #define LINKTYPE_IEEE802_11 105 /* http://www.tcpdump.org/linktypes.html */
class decode_mac_impl : public decode_mac { class decode_mac_impl : public decode_mac
{
public: public:
decode_mac_impl(bool log, bool debug) : decode_mac_impl(bool log, bool debug)
block("decode_mac", : block("decode_mac",
gr::io_signature::make(1, 1, 48), gr::io_signature::make(1, 1, 48),
gr::io_signature::make(0, 0, 0)), gr::io_signature::make(0, 0, 0)),
d_log(log), d_log(log),
@@ -40,14 +41,17 @@ decode_mac_impl(bool log, bool debug) :
d_freq_offset(0.0), d_freq_offset(0.0),
d_ofdm(BPSK_1_2), d_ofdm(BPSK_1_2),
d_frame(d_ofdm, 0), d_frame(d_ofdm, 0),
d_frame_complete(true) { d_frame_complete(true)
{
message_port_register_out(pmt::mp("out")); message_port_register_out(pmt::mp("out"));
} }
int general_work (int noutput_items, gr_vector_int& ninput_items, int general_work(int noutput_items,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items, gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items) { gr_vector_void_star& output_items)
{
const uint8_t* in = (const uint8_t*)input_items[0]; const uint8_t* in = (const uint8_t*)input_items[0];
@@ -60,24 +64,34 @@ int general_work (int noutput_items, gr_vector_int& ninput_items,
while (i < ninput_items[0]) { while (i < ninput_items[0]) {
get_tags_in_range(tags, 0, nread + i, nread + i + 1, get_tags_in_range(
pmt::string_to_symbol("wifi_start")); tags, 0, nread + i, nread + i + 1, pmt::string_to_symbol("wifi_start"));
if (tags.size()) { if (tags.size()) {
if (d_frame_complete == false) { if (d_frame_complete == false) {
dout << "Warning: starting to receive new frame before old frame was complete" << std::endl; dout << "Warning: starting to receive new frame before old frame was "
dout << "Already copied " << copied << " out of " << d_frame.n_sym << " symbols of last frame" << std::endl; "complete"
<< std::endl;
dout << "Already copied " << copied << " out of " << d_frame.n_sym
<< " symbols of last frame" << std::endl;
} }
d_frame_complete = false; d_frame_complete = false;
pmt::pmt_t dict = tags[0].value; pmt::pmt_t dict = tags[0].value;
int len_data = pmt::to_uint64(pmt::dict_ref(dict, pmt::mp("frame_bytes"), pmt::from_uint64(MAX_PSDU_SIZE+1))); int len_data = pmt::to_uint64(pmt::dict_ref(
int encoding = pmt::to_uint64(pmt::dict_ref(dict, pmt::mp("encoding"), pmt::from_uint64(0))); dict, pmt::mp("frame_bytes"), pmt::from_uint64(MAX_PSDU_SIZE + 1)));
d_snr = pmt::to_double(pmt::dict_ref(dict, pmt::mp("snr"), pmt::from_double(0))); int encoding = pmt::to_uint64(
d_nom_freq = pmt::to_double(pmt::dict_ref(dict, pmt::mp("freq"), pmt::from_double(0))); pmt::dict_ref(dict, pmt::mp("encoding"), pmt::from_uint64(0)));
d_freq_offset = pmt::to_double(pmt::dict_ref(dict, pmt::mp("freq_offset"), pmt::from_double(0))); d_snr = pmt::to_double(
d_beta = pmt::to_double(pmt::dict_ref(dict, pmt::mp("beta"), pmt::from_double(0))); pmt::dict_ref(dict, pmt::mp("snr"), pmt::from_double(0)));
d_csi = pmt::c32vector_elements(pmt::dict_ref(dict, pmt::mp("csi"), pmt::make_c32vector(52, 0))); d_nom_freq = pmt::to_double(
pmt::dict_ref(dict, pmt::mp("freq"), pmt::from_double(0)));
d_freq_offset = pmt::to_double(
pmt::dict_ref(dict, pmt::mp("freq_offset"), pmt::from_double(0)));
d_beta = pmt::to_double(
pmt::dict_ref(dict, pmt::mp("beta"), pmt::from_double(0)));
d_csi = pmt::c32vector_elements(
pmt::dict_ref(dict, pmt::mp("csi"), pmt::make_c32vector(52, 0)));
ofdm_param ofdm = ofdm_param((Encoding)encoding); ofdm_param ofdm = ofdm_param((Encoding)encoding);
frame_param frame = frame_param(ofdm, len_data); frame_param frame = frame_param(ofdm, len_data);
@@ -86,16 +100,17 @@ int general_work (int noutput_items, gr_vector_int& ninput_items,
d_ofdm = ofdm; d_ofdm = ofdm;
d_frame = frame; d_frame = frame;
copied = 0; copied = 0;
dout << "Decode MAC: frame start -- len " << len_data dout << "Decode MAC: frame start -- len " << len_data << " symbols "
<< " symbols " << frame.n_sym << " encoding " << frame.n_sym << " encoding " << encoding << std::endl;
<< encoding << std::endl;
} else { } else {
dout << "Dropping frame which is too large (symbols or bits)" << std::endl; dout << "Dropping frame which is too large (symbols or bits)"
<< std::endl;
} }
} }
if (copied < d_frame.n_sym) { if (copied < d_frame.n_sym) {
dout << "copy one symbol, copied " << copied << " out of " << d_frame.n_sym << std::endl; dout << "copy one symbol, copied " << copied << " out of "
<< d_frame.n_sym << std::endl;
std::memcpy(d_rx_symbols + (copied * 48), in, 48); std::memcpy(d_rx_symbols + (copied * 48), in, 48);
copied++; copied++;
@@ -118,7 +133,8 @@ int general_work (int noutput_items, gr_vector_int& ninput_items,
return 0; return 0;
} }
void decode() { void decode()
{
for (int i = 0; i < d_frame.n_sym * 48; i++) { for (int i = 0; i < d_frame.n_sym * 48; i++) {
for (int k = 0; k < d_ofdm.n_bpsc; k++) { for (int k = 0; k < d_ofdm.n_bpsc; k++) {
@@ -139,8 +155,8 @@ void decode() {
return; return;
} }
mylog(boost::format("encoding: %1% - length: %2% - symbols: %3%") mylog(boost::format("encoding: %1% - length: %2% - symbols: %3%") %
% d_ofdm.encoding % d_frame.psdu_size % d_frame.n_sym); d_ofdm.encoding % d_frame.psdu_size % d_frame.n_sym);
// create PDU // create PDU
pmt::pmt_t blob = pmt::make_blob(out_bytes + 2, d_frame.psdu_size - 4); pmt::pmt_t blob = pmt::make_blob(out_bytes + 2, d_frame.psdu_size - 4);
@@ -156,7 +172,8 @@ void decode() {
message_port_pub(pmt::mp("out"), pmt::cons(dict, blob)); message_port_pub(pmt::mp("out"), pmt::cons(dict, blob));
} }
void deinterleave() { void deinterleave()
{
int n_cbps = d_ofdm.n_cbps; int n_cbps = d_ofdm.n_cbps;
int first[n_cbps]; int first[n_cbps];
@@ -174,13 +191,15 @@ void deinterleave() {
int count = 0; int count = 0;
for (int i = 0; i < d_frame.n_sym; i++) { for (int i = 0; i < d_frame.n_sym; i++) {
for (int k = 0; k < n_cbps; k++) { for (int k = 0; k < n_cbps; k++) {
d_deinterleaved_bits[i * n_cbps + second[first[k]]] = d_rx_bits[i * n_cbps + k]; d_deinterleaved_bits[i * n_cbps + second[first[k]]] =
d_rx_bits[i * n_cbps + k];
} }
} }
} }
void descramble (uint8_t *decoded_bits) { void descramble(uint8_t* decoded_bits)
{
int state = 0; int state = 0;
std::memset(out_bytes, 0, d_frame.psdu_size + 2); std::memset(out_bytes, 0, d_frame.psdu_size + 2);
@@ -203,12 +222,14 @@ void descramble (uint8_t *decoded_bits) {
} }
} }
void print_output() { void print_output()
{
dout << std::endl; dout << std::endl;
dout << "psdu size" << d_frame.psdu_size << std::endl; dout << "psdu size" << d_frame.psdu_size << std::endl;
for (int i = 2; i < d_frame.psdu_size + 2; i++) { for (int i = 2; i < d_frame.psdu_size + 2; i++) {
dout << std::setfill('0') << std::setw(2) << std::hex << ((unsigned int)out_bytes[i] & 0xFF) << std::dec << " "; dout << std::setfill('0') << std::setw(2) << std::hex
<< ((unsigned int)out_bytes[i] & 0xFF) << std::dec << " ";
if (i % 16 == 15) { if (i % 16 == 15) {
dout << std::endl; dout << std::endl;
} }
@@ -246,7 +267,7 @@ private:
bool d_frame_complete; bool d_frame_complete;
}; };
decode_mac::sptr decode_mac::sptr decode_mac::make(bool log, bool debug)
decode_mac::make(bool log, bool debug) { {
return gnuradio::get_initial_sptr(new decode_mac_impl(log, debug)); return gnuradio::get_initial_sptr(new decode_mac_impl(log, debug));
} }
+14 -18
View File
@@ -21,27 +21,23 @@
using namespace gr::ieee802_11::equalizer; using namespace gr::ieee802_11::equalizer;
const gr_complex base::LONG[] = { const gr_complex base::LONG[] = { 0, 0, 0, 0, 0, 0, 1, 1, -1, -1, 1, 1, -1,
0, 0, 0, 0, 0, 0, 1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1,
1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, 1, 0, 1, -1, -1, 1, 1, -1,
1, -1, -1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1,
1, 1, 0, 1, -1, -1, 1, 1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
-1, 1, -1, -1, -1, -1, -1, 1, 1, -1,
-1, 1, -1, 1, -1, 1, 1, 1, 1, 0,
0, 0, 0, 0
};
const gr_complex base::POLARITY[127] = { const gr_complex base::POLARITY[127] = {
1, 1, 1, 1,-1,-1,-1, 1,-1,-1,-1,-1, 1, 1,-1, 1, 1, 1, 1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1,
-1,-1, 1, 1,-1, 1, 1,-1, 1, 1, 1, 1, 1, 1,-1, 1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, 1,
1, 1,-1, 1, 1,-1,-1, 1, 1, 1,-1, 1,-1,-1,-1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, -1,
-1, 1,-1,-1, 1,-1,-1, 1, 1, 1, 1, 1,-1,-1, 1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 1, 1,
-1,-1, 1,-1, 1,-1, 1, 1,-1,-1,-1, 1, 1,-1,-1,-1, 1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1,
-1, 1,-1,-1, 1,-1, 1, 1, 1, 1,-1, 1,-1, 1,-1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1
-1,-1,-1,-1,-1, 1,-1, 1, 1,-1, 1,-1, 1, 1, 1,-1, };
-1, 1,-1,-1,-1, 1, 1, 1,-1,-1,-1,-1,-1,-1,-1 };
std::vector<gr_complex> base::get_csi() { std::vector<gr_complex> base::get_csi()
{
std::vector<gr_complex> csi; std::vector<gr_complex> csi;
csi.reserve(52); csi.reserve(52);
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
+9 -4
View File
@@ -18,17 +18,22 @@
#ifndef INCLUDED_IEEE802_11_EQUALIZER_BASE_H #ifndef INCLUDED_IEEE802_11_EQUALIZER_BASE_H
#define INCLUDED_IEEE802_11_EQUALIZER_BASE_H #define INCLUDED_IEEE802_11_EQUALIZER_BASE_H
#include <gnuradio/gr_complex.h>
#include <gnuradio/digital/constellation.h> #include <gnuradio/digital/constellation.h>
#include <gnuradio/gr_complex.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
namespace equalizer { namespace equalizer {
class base { class base
{
public: public:
virtual ~base(){}; virtual ~base(){};
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) = 0; virtual void equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod) = 0;
virtual double get_snr() = 0; virtual double get_snr() = 0;
static const gr_complex POLARITY[127]; static const gr_complex POLARITY[127];
@@ -41,7 +46,7 @@ protected:
gr_complex d_H[64]; gr_complex d_H[64];
}; };
} /* namespace channel_estimation */ } // namespace equalizer
} /* namespace ieee802_11 */ } /* namespace ieee802_11 */
} /* namespace gr */ } /* namespace gr */
+17 -10
View File
@@ -19,7 +19,12 @@
using namespace gr::ieee802_11::equalizer; using namespace gr::ieee802_11::equalizer;
void comb::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) { void comb::equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod)
{
gr_complex pilot[4]; gr_complex pilot[4];
@@ -43,13 +48,17 @@ void comb::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, b
if (i <= 11) { if (i <= 11) {
H = gr_complex((11 - i) / 11.0, 0) * avg + gr_complex(i / 11.0, 0) * pilot[0]; H = gr_complex((11 - i) / 11.0, 0) * avg + gr_complex(i / 11.0, 0) * pilot[0];
} else if (i <= 25) { } else if (i <= 25) {
H = gr_complex((25-i) / 14.0, 0) * pilot[0] + gr_complex((i-11) / 14.0, 0) * pilot[1]; H = gr_complex((25 - i) / 14.0, 0) * pilot[0] +
gr_complex((i - 11) / 14.0, 0) * pilot[1];
} else if (i <= 39) { } else if (i <= 39) {
H = gr_complex((39-i) / 14.0, 0) * pilot[1] + gr_complex((i-25) / 14.0, 0) * pilot[2]; H = gr_complex((39 - i) / 14.0, 0) * pilot[1] +
gr_complex((i - 25) / 14.0, 0) * pilot[2];
} else if (i <= 53) { } else if (i <= 53) {
H = gr_complex((53-i) / 14.0, 0) * pilot[2] + gr_complex((i-39) / 14.0, 0) * pilot[3]; H = gr_complex((53 - i) / 14.0, 0) * pilot[2] +
gr_complex((i - 39) / 14.0, 0) * pilot[3];
} else { } else {
H = gr_complex((64-i) / 11.0, 0) * pilot[3] + gr_complex((i-53) / 11.0, 0) * avg; H = gr_complex((64 - i) / 11.0, 0) * pilot[3] +
gr_complex((i - 53) / 11.0, 0) * avg;
} }
if (n == 0) { if (n == 0) {
@@ -61,7 +70,8 @@ void comb::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, b
int c = 0; int c = 0;
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
if( (i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) || (i < 6) || ( i > 58)) { if ((i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) || (i < 6) ||
(i > 58)) {
continue; continue;
} else { } else {
symbols[c] = in[i] / d_H[i]; symbols[c] = in[i] / d_H[i];
@@ -71,7 +81,4 @@ void comb::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, b
} }
} }
double double comb::get_snr() { return 42; }
comb::get_snr() {
return 42;
}
+8 -4
View File
@@ -24,18 +24,22 @@ namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
namespace equalizer { namespace equalizer {
class comb: public base { class comb : public base
{
public: public:
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod); virtual void equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod);
double get_snr(); double get_snr();
private: private:
const double alpha = 0.2; const double alpha = 0.2;
}; };
} /* namespace channel_estimation */ } // namespace equalizer
} /* namespace ieee802_11 */ } /* namespace ieee802_11 */
} /* namespace gr */ } /* namespace gr */
#endif /* INCLUDED_IEEE802_11_EQUALIZER_COMB_H */ #endif /* INCLUDED_IEEE802_11_EQUALIZER_COMB_H */
+11 -7
View File
@@ -21,7 +21,12 @@
using namespace gr::ieee802_11::equalizer; using namespace gr::ieee802_11::equalizer;
void lms::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) { void lms::equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod)
{
if (n == 0) { if (n == 0) {
std::memcpy(d_H, in, 64 * sizeof(gr_complex)); std::memcpy(d_H, in, 64 * sizeof(gr_complex));
@@ -44,21 +49,20 @@ void lms::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, bo
} else { } else {
int c = 0; int c = 0;
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
if( (i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) || (i < 6) || ( i > 58)) { if ((i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) ||
(i < 6) || (i > 58)) {
continue; continue;
} else { } else {
symbols[c] = in[i] / d_H[i]; symbols[c] = in[i] / d_H[i];
bits[c] = mod->decision_maker(&symbols[c]); bits[c] = mod->decision_maker(&symbols[c]);
gr_complex point; gr_complex point;
mod->map_to_points(bits[c], &point); mod->map_to_points(bits[c], &point);
d_H[i] = gr_complex(1-alpha,0) * d_H[i] + gr_complex(alpha,0) * in[i] / point; d_H[i] = gr_complex(1 - alpha, 0) * d_H[i] +
gr_complex(alpha, 0) * in[i] / point;
c++; c++;
} }
} }
} }
} }
double double lms::get_snr() { return d_snr; }
lms::get_snr() {
return d_snr;
}
+9 -3
View File
@@ -25,9 +25,15 @@ namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
namespace equalizer { namespace equalizer {
class lms: public base { class lms : public base
{
public: public:
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod); virtual void equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod);
private: private:
double get_snr(); double get_snr();
@@ -35,7 +41,7 @@ private:
const double alpha = 0.5; const double alpha = 0.5;
}; };
} /* namespace channel_estimation */ } // namespace equalizer
} /* namespace ieee802_11 */ } /* namespace ieee802_11 */
} /* namespace gr */ } /* namespace gr */
+9 -5
View File
@@ -21,7 +21,12 @@
using namespace gr::ieee802_11::equalizer; using namespace gr::ieee802_11::equalizer;
void ls::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) { void ls::equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod)
{
if (n == 0) { if (n == 0) {
std::memcpy(d_H, in, 64 * sizeof(gr_complex)); std::memcpy(d_H, in, 64 * sizeof(gr_complex));
@@ -45,7 +50,8 @@ void ls::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boo
int c = 0; int c = 0;
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
if( (i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) || (i < 6) || ( i > 58)) { if ((i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) ||
(i < 6) || (i > 58)) {
continue; continue;
} else { } else {
symbols[c] = in[i] / d_H[i]; symbols[c] = in[i] / d_H[i];
@@ -56,6 +62,4 @@ void ls::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boo
} }
} }
double ls::get_snr() { double ls::get_snr() { return d_snr; }
return d_snr;
}
+9 -4
View File
@@ -25,17 +25,22 @@ namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
namespace equalizer { namespace equalizer {
class ls: public base { class ls : public base
{
public: public:
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod); virtual void equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod);
virtual double get_snr(); virtual double get_snr();
private: private:
double d_snr; double d_snr;
}; };
} /* namespace channel_estimation */ } // namespace equalizer
} /* namespace ieee802_11 */ } /* namespace ieee802_11 */
} /* namespace gr */ } /* namespace gr */
#endif /* INCLUDED_IEEE802_11_EQUALIZER_LS_H */ #endif /* INCLUDED_IEEE802_11_EQUALIZER_LS_H */
+11 -7
View File
@@ -21,7 +21,12 @@
using namespace gr::ieee802_11::equalizer; using namespace gr::ieee802_11::equalizer;
void sta::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod) { void sta::equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod)
{
if (n == 0) { if (n == 0) {
std::memcpy(d_H, in, 64 * sizeof(gr_complex)); std::memcpy(d_H, in, 64 * sizeof(gr_complex));
@@ -55,7 +60,8 @@ void sta::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, bo
int c = 0; int c = 0;
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
if( (i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) || (i < 6) || ( i > 58)) { if ((i == 11) || (i == 25) || (i == 32) || (i == 39) || (i == 53) ||
(i < 6) || (i > 58)) {
continue; continue;
} else { } else {
symbols[c] = in[i] / d_H[i]; symbols[c] = in[i] / d_H[i];
@@ -84,12 +90,10 @@ void sta::equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, bo
if ((i < 6) || (i > 58)) { if ((i < 6) || (i > 58)) {
continue; continue;
} }
d_H[i] = gr_complex(1-alpha,0) * d_H[i] + gr_complex(alpha,0) * H_update[i]; d_H[i] =
gr_complex(1 - alpha, 0) * d_H[i] + gr_complex(alpha, 0) * H_update[i];
} }
} }
} }
double double sta::get_snr() { return d_snr; }
sta::get_snr() {
return d_snr;
}
+8 -3
View File
@@ -25,9 +25,14 @@ namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
namespace equalizer { namespace equalizer {
class sta: public base { class sta : public base
{
public: public:
virtual void equalize(gr_complex *in, int n, gr_complex *symbols, uint8_t *bits, boost::shared_ptr<gr::digital::constellation> mod); virtual void equalize(gr_complex* in,
int n,
gr_complex* symbols,
uint8_t* bits,
boost::shared_ptr<gr::digital::constellation> mod);
double get_snr(); double get_snr();
private: private:
@@ -37,7 +42,7 @@ private:
const int beta = 2; const int beta = 2;
}; };
} /* namespace channel_estimation */ } // namespace equalizer
} /* namespace ieee802_11 */ } /* namespace ieee802_11 */
} /* namespace gr */ } /* namespace gr */
+19 -15
View File
@@ -17,30 +17,35 @@
#include "ether_encap_impl.h" #include "ether_encap_impl.h"
#include "utils.h" #include "utils.h"
#include <gnuradio/io_signature.h>
#include <gnuradio/block_detail.h> #include <gnuradio/block_detail.h>
#include <gnuradio/io_signature.h>
#include <string> #include <string>
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
ether_encap_impl::ether_encap_impl(bool debug) : ether_encap_impl::ether_encap_impl(bool debug)
block("ether_encap", : block("ether_encap",
gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0)), gr::io_signature::make(0, 0, 0)),
d_debug(debug), d_debug(debug),
d_last_seq(123) { d_last_seq(123)
{
message_port_register_out(pmt::mp("to tap")); message_port_register_out(pmt::mp("to tap"));
message_port_register_out(pmt::mp("to wifi")); message_port_register_out(pmt::mp("to wifi"));
message_port_register_in(pmt::mp("from tap")); message_port_register_in(pmt::mp("from tap"));
set_msg_handler(pmt::mp("from tap"), boost::bind(&ether_encap_impl::from_tap, this, boost::placeholders::_1)); set_msg_handler(
pmt::mp("from tap"),
boost::bind(&ether_encap_impl::from_tap, this, boost::placeholders::_1));
message_port_register_in(pmt::mp("from wifi")); message_port_register_in(pmt::mp("from wifi"));
set_msg_handler(pmt::mp("from wifi"), boost::bind(&ether_encap_impl::from_wifi, this, boost::placeholders::_1)); set_msg_handler(
pmt::mp("from wifi"),
boost::bind(&ether_encap_impl::from_wifi, this, boost::placeholders::_1));
} }
void void ether_encap_impl::from_wifi(pmt::pmt_t msg)
ether_encap_impl::from_wifi(pmt::pmt_t msg) { {
msg = pmt::cdr(msg); msg = pmt::cdr(msg);
@@ -92,8 +97,8 @@ ether_encap_impl::from_wifi(pmt::pmt_t msg) {
free(buf); free(buf);
} }
void void ether_encap_impl::from_tap(pmt::pmt_t msg)
ether_encap_impl::from_tap(pmt::pmt_t msg) { {
size_t len = pmt::blob_length(pmt::cdr(msg)); size_t len = pmt::blob_length(pmt::cdr(msg));
const char* data = static_cast<const char*>(pmt::blob_data(pmt::cdr(msg))); const char* data = static_cast<const char*>(pmt::blob_data(pmt::cdr(msg)));
@@ -112,7 +117,8 @@ ether_encap_impl::from_tap(pmt::pmt_t msg) {
buf[5] = 0x00; buf[5] = 0x00;
buf[6] = 0x08; buf[6] = 0x08;
buf[7] = 0x00; buf[7] = 0x00;
std::memcpy(buf + 8, data + sizeof(ethernet_header), len - sizeof(ethernet_header)); std::memcpy(
buf + 8, data + sizeof(ethernet_header), len - sizeof(ethernet_header));
pmt::pmt_t blob = pmt::make_blob(buf, len + 8 - sizeof(ethernet_header)); pmt::pmt_t blob = pmt::make_blob(buf, len + 8 - sizeof(ethernet_header));
message_port_pub(pmt::mp("to wifi"), pmt::cons(pmt::PMT_NIL, blob)); message_port_pub(pmt::mp("to wifi"), pmt::cons(pmt::PMT_NIL, blob));
break; break;
@@ -124,11 +130,9 @@ ether_encap_impl::from_tap(pmt::pmt_t msg) {
std::cout << "unknown ether type" << std::endl; std::cout << "unknown ether type" << std::endl;
break; break;
} }
} }
ether_encap::sptr ether_encap::sptr ether_encap::make(bool debug)
ether_encap::make(bool debug) { {
return gnuradio::get_initial_sptr(new ether_encap_impl(debug)); return gnuradio::get_initial_sptr(new ether_encap_impl(debug));
} }
+2 -2
View File
@@ -28,7 +28,8 @@ namespace ieee802_11 {
uint16_t type; uint16_t type;
} __attribute__((packed)); } __attribute__((packed));
class ether_encap_impl : public ether_encap { class ether_encap_impl : public ether_encap
{
public: public:
ether_encap_impl(bool debug); ether_encap_impl(bool debug);
@@ -45,4 +46,3 @@ namespace ieee802_11 {
} // namespace gr } // namespace gr
#endif /* INCLUDED_IEEE802_11_ETHER_ENCAP_IMPL_H */ #endif /* INCLUDED_IEEE802_11_ETHER_ENCAP_IMPL_H */
+10 -7
View File
@@ -22,20 +22,23 @@
#include "config.h" #include "config.h"
#endif #endif
#include <gnuradio/io_signature.h>
#include "extract_csi_impl.h" #include "extract_csi_impl.h"
#include <gnuradio/io_signature.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
extract_csi::sptr extract_csi::make() { extract_csi::sptr extract_csi::make()
{
return gnuradio::get_initial_sptr(new extract_csi_impl()); return gnuradio::get_initial_sptr(new extract_csi_impl());
} }
extract_csi_impl::extract_csi_impl() extract_csi_impl::extract_csi_impl()
: gr::sync_block("extract_csi", gr::io_signature::make(0, 0, 0), : gr::sync_block("extract_csi",
gr::io_signature::make(1, 1, 52 * sizeof(gr_complex))) { gr::io_signature::make(0, 0, 0),
gr::io_signature::make(1, 1, 52 * sizeof(gr_complex)))
{
message_port_register_in(pmt::mp("pdu in")); message_port_register_in(pmt::mp("pdu in"));
} }
@@ -43,7 +46,8 @@ extract_csi_impl::~extract_csi_impl() {}
int extract_csi_impl::work(int noutput_items, int extract_csi_impl::work(int noutput_items,
gr_vector_const_void_star& input_items, gr_vector_const_void_star& input_items,
gr_vector_void_star &output_items) { gr_vector_void_star& output_items)
{
pmt::pmt_t pdu(delete_head_nowait(pmt::mp("pdu in"))); pmt::pmt_t pdu(delete_head_nowait(pmt::mp("pdu in")));
if (pdu.get() == NULL) if (pdu.get() == NULL)
@@ -57,8 +61,7 @@ int extract_csi_impl::work(int noutput_items,
if (!pmt::dict_has_key(d_meta, pmt::mp("csi"))) if (!pmt::dict_has_key(d_meta, pmt::mp("csi")))
return 0; return 0;
d_csi = pmt::c32vector_elements( d_csi = pmt::c32vector_elements(pmt::dict_ref(d_meta, pmt::mp("csi"), pmt::PMT_NIL));
pmt::dict_ref(d_meta, pmt::mp("csi"), pmt::PMT_NIL));
gr_complex* out = (gr_complex*)output_items[0]; gr_complex* out = (gr_complex*)output_items[0];
+4 -2
View File
@@ -26,7 +26,8 @@
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
class extract_csi_impl : public extract_csi { class extract_csi_impl : public extract_csi
{
private: private:
pmt::pmt_t d_meta; pmt::pmt_t d_meta;
std::vector<gr_complex> d_csi; std::vector<gr_complex> d_csi;
@@ -35,7 +36,8 @@ public:
extract_csi_impl(); extract_csi_impl();
~extract_csi_impl(); ~extract_csi_impl();
int work(int noutput_items, gr_vector_const_void_star &input_items, int work(int noutput_items,
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items); gr_vector_void_star& output_items);
}; };
+73 -61
View File
@@ -15,12 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "frame_equalizer_impl.h"
#include "equalizer/base.h" #include "equalizer/base.h"
#include "equalizer/comb.h" #include "equalizer/comb.h"
#include "equalizer/lms.h" #include "equalizer/lms.h"
#include "equalizer/ls.h" #include "equalizer/ls.h"
#include "equalizer/sta.h" #include "equalizer/sta.h"
#include "frame_equalizer_impl.h"
#include "utils.h" #include "utils.h"
#include <gnuradio/io_signature.h> #include <gnuradio/io_signature.h>
@@ -28,19 +28,28 @@ namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
frame_equalizer::sptr frame_equalizer::sptr
frame_equalizer::make(Equalizer algo, double freq, double bw, bool log, bool debug) { frame_equalizer::make(Equalizer algo, double freq, double bw, bool log, bool debug)
return gnuradio::get_initial_sptr {
(new frame_equalizer_impl(algo, freq, bw, log, debug)); return gnuradio::get_initial_sptr(
new frame_equalizer_impl(algo, freq, bw, log, debug));
} }
frame_equalizer_impl::frame_equalizer_impl(Equalizer algo, double freq, double bw, bool log, bool debug) : frame_equalizer_impl::frame_equalizer_impl(
gr::block("frame_equalizer", Equalizer algo, double freq, double bw, bool log, bool debug)
: gr::block("frame_equalizer",
gr::io_signature::make(1, 1, 64 * sizeof(gr_complex)), gr::io_signature::make(1, 1, 64 * sizeof(gr_complex)),
gr::io_signature::make(1, 1, 48)), gr::io_signature::make(1, 1, 48)),
d_current_symbol(0), d_log(log), d_debug(debug), d_equalizer(NULL), d_current_symbol(0),
d_freq(freq), d_bw(bw), d_frame_bytes(0), d_frame_symbols(0), d_log(log),
d_freq_offset_from_synclong(0.0) { d_debug(debug),
d_equalizer(NULL),
d_freq(freq),
d_bw(bw),
d_frame_bytes(0),
d_frame_symbols(0),
d_freq_offset_from_synclong(0.0)
{
message_port_register_out(pmt::mp("symbols")); message_port_register_out(pmt::mp("symbols"));
@@ -55,12 +64,11 @@ frame_equalizer_impl::frame_equalizer_impl(Equalizer algo, double freq, double b
set_algorithm(algo); set_algorithm(algo);
} }
frame_equalizer_impl::~frame_equalizer_impl() { frame_equalizer_impl::~frame_equalizer_impl() {}
}
void void frame_equalizer_impl::set_algorithm(Equalizer algo)
frame_equalizer_impl::set_algorithm(Equalizer algo) { {
gr::thread::scoped_lock lock(d_mutex); gr::thread::scoped_lock lock(d_mutex);
delete d_equalizer; delete d_equalizer;
@@ -87,28 +95,29 @@ frame_equalizer_impl::set_algorithm(Equalizer algo) {
} }
} }
void void frame_equalizer_impl::set_bandwidth(double bw)
frame_equalizer_impl::set_bandwidth(double bw) { {
gr::thread::scoped_lock lock(d_mutex); gr::thread::scoped_lock lock(d_mutex);
d_bw = bw; d_bw = bw;
} }
void void frame_equalizer_impl::set_frequency(double freq)
frame_equalizer_impl::set_frequency(double freq) { {
gr::thread::scoped_lock lock(d_mutex); gr::thread::scoped_lock lock(d_mutex);
d_freq = freq; d_freq = freq;
} }
void void frame_equalizer_impl::forecast(int noutput_items,
frame_equalizer_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) { gr_vector_int& ninput_items_required)
{
ninput_items_required[0] = noutput_items; ninput_items_required[0] = noutput_items;
} }
int int frame_equalizer_impl::general_work(int noutput_items,
frame_equalizer_impl::general_work (int noutput_items,
gr_vector_int& ninput_items, gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items, gr_vector_const_void_star& input_items,
gr_vector_void_star &output_items) { gr_vector_void_star& output_items)
{
gr::thread::scoped_lock lock(d_mutex); gr::thread::scoped_lock lock(d_mutex);
@@ -120,7 +129,8 @@ frame_equalizer_impl::general_work (int noutput_items,
gr_complex symbols[48]; gr_complex symbols[48];
gr_complex current_symbol[64]; gr_complex current_symbol[64];
dout << "FRAME EQUALIZER: input " << ninput_items[0] << " output " << noutput_items << std::endl; dout << "FRAME EQUALIZER: input " << ninput_items[0] << " output " << noutput_items
<< std::endl;
while ((i < ninput_items[0]) && (o < noutput_items)) { while ((i < ninput_items[0]) && (o < noutput_items)) {
@@ -132,7 +142,8 @@ frame_equalizer_impl::general_work (int noutput_items,
d_frame_symbols = 0; d_frame_symbols = 0;
d_frame_mod = d_bpsk; d_frame_mod = d_bpsk;
d_freq_offset_from_synclong = pmt::to_double(tags.front().value) * d_bw / (2 * M_PI); d_freq_offset_from_synclong =
pmt::to_double(tags.front().value) * d_bw / (2 * M_PI);
d_epsilon0 = pmt::to_double(tags.front().value) * d_bw / (2 * M_PI * d_freq); d_epsilon0 = pmt::to_double(tags.front().value) * d_bw / (2 * M_PI * d_freq);
d_er = 0; d_er = 0;
@@ -149,29 +160,24 @@ frame_equalizer_impl::general_work (int noutput_items,
// compensate sampling offset // compensate sampling offset
for (int i = 0; i < 64; i++) { for (int i = 0; i < 64; i++) {
current_symbol[i] *= exp(gr_complex(0, 2*M_PI*d_current_symbol*80*(d_epsilon0 + d_er)*(i-32)/64)); current_symbol[i] *= exp(gr_complex(0,
2 * M_PI * d_current_symbol * 80 *
(d_epsilon0 + d_er) * (i - 32) / 64));
} }
gr_complex p = equalizer::base::POLARITY[(d_current_symbol - 2) % 127]; gr_complex p = equalizer::base::POLARITY[(d_current_symbol - 2) % 127];
double beta; double beta;
if (d_current_symbol < 2) { if (d_current_symbol < 2) {
beta = arg( beta = arg(current_symbol[11] - current_symbol[25] + current_symbol[39] +
current_symbol[11] -
current_symbol[25] +
current_symbol[39] +
current_symbol[53]); current_symbol[53]);
} else { } else {
beta = arg( beta = arg((current_symbol[11] * p) + (current_symbol[39] * p) +
(current_symbol[11] * p) + (current_symbol[25] * p) + (current_symbol[53] * -p));
(current_symbol[39] * p) +
(current_symbol[25] * p) +
(current_symbol[53] * -p));
} }
double er = arg( double er = arg((conj(d_prev_pilots[0]) * current_symbol[11] * p) +
(conj(d_prev_pilots[0]) * current_symbol[11] * p) +
(conj(d_prev_pilots[1]) * current_symbol[25] * p) + (conj(d_prev_pilots[1]) * current_symbol[25] * p) +
(conj(d_prev_pilots[2]) * current_symbol[39] * p) + (conj(d_prev_pilots[2]) * current_symbol[39] * p) +
(conj(d_prev_pilots[3]) * current_symbol[53] * -p)); (conj(d_prev_pilots[3]) * current_symbol[53] * -p));
@@ -203,8 +209,8 @@ frame_equalizer_impl::general_work (int noutput_items,
} }
// do equalization // do equalization
d_equalizer->equalize(current_symbol, d_current_symbol, d_equalizer->equalize(
symbols, out + o * 48, d_frame_mod); current_symbol, d_current_symbol, symbols, out + o * 48, d_frame_mod);
// signal field // signal field
if (d_current_symbol == 2) { if (d_current_symbol == 2) {
@@ -212,17 +218,24 @@ frame_equalizer_impl::general_work (int noutput_items,
if (decode_signal_field(out + o * 48)) { if (decode_signal_field(out + o * 48)) {
pmt::pmt_t dict = pmt::make_dict(); pmt::pmt_t dict = pmt::make_dict();
dict = pmt::dict_add(dict, pmt::mp("frame_bytes"), pmt::from_uint64(d_frame_bytes)); dict = pmt::dict_add(
dict = pmt::dict_add(dict, pmt::mp("encoding"), pmt::from_uint64(d_frame_encoding)); dict, pmt::mp("frame_bytes"), pmt::from_uint64(d_frame_bytes));
dict = pmt::dict_add(dict, pmt::mp("snr"), pmt::from_double(d_equalizer->get_snr())); dict = pmt::dict_add(
dict, pmt::mp("encoding"), pmt::from_uint64(d_frame_encoding));
dict = pmt::dict_add(
dict, pmt::mp("snr"), pmt::from_double(d_equalizer->get_snr()));
dict = pmt::dict_add(dict, pmt::mp("freq"), pmt::from_double(d_freq)); dict = pmt::dict_add(dict, pmt::mp("freq"), pmt::from_double(d_freq));
dict = pmt::dict_add(dict, pmt::mp("freq_offset"), pmt::from_double(d_freq_offset_from_synclong)); dict = pmt::dict_add(dict,
pmt::mp("freq_offset"),
pmt::from_double(d_freq_offset_from_synclong));
dict = pmt::dict_add(dict, pmt::mp("beta"), pmt::from_double(beta)); dict = pmt::dict_add(dict, pmt::mp("beta"), pmt::from_double(beta));
std::vector<gr_complex> csi = d_equalizer->get_csi(); std::vector<gr_complex> csi = d_equalizer->get_csi();
dict = pmt::dict_add(dict, pmt::mp("csi"), pmt::init_c32vector(csi.size(), csi)); dict = pmt::dict_add(
dict, pmt::mp("csi"), pmt::init_c32vector(csi.size(), csi));
add_item_tag(0, nitems_written(0) + o, add_item_tag(0,
nitems_written(0) + o,
pmt::string_to_symbol("wifi_start"), pmt::string_to_symbol("wifi_start"),
dict, dict,
pmt::string_to_symbol(alias())); pmt::string_to_symbol(alias()));
@@ -232,7 +245,9 @@ frame_equalizer_impl::general_work (int noutput_items,
if (d_current_symbol > 2) { if (d_current_symbol > 2) {
o++; o++;
pmt::pmt_t pdu = pmt::make_dict(); pmt::pmt_t pdu = pmt::make_dict();
message_port_pub(pmt::mp("symbols"), pmt::cons(pmt::make_dict(), pmt::init_c32vector(48, symbols))); message_port_pub(
pmt::mp("symbols"),
pmt::cons(pmt::make_dict(), pmt::init_c32vector(48, symbols)));
} }
i++; i++;
@@ -243,8 +258,8 @@ frame_equalizer_impl::general_work (int noutput_items,
return o; return o;
} }
bool bool frame_equalizer_impl::decode_signal_field(uint8_t* rx_bits)
frame_equalizer_impl::decode_signal_field(uint8_t *rx_bits) { {
static ofdm_param ofdm(BPSK_1_2); static ofdm_param ofdm(BPSK_1_2);
static frame_param frame(ofdm, 0); static frame_param frame(ofdm, 0);
@@ -255,15 +270,15 @@ frame_equalizer_impl::decode_signal_field(uint8_t *rx_bits) {
return parse_signal(decoded_bits); return parse_signal(decoded_bits);
} }
void void frame_equalizer_impl::deinterleave(uint8_t* rx_bits)
frame_equalizer_impl::deinterleave(uint8_t *rx_bits) { {
for (int i = 0; i < 48; i++) { for (int i = 0; i < 48; i++) {
d_deinterleaved[i] = rx_bits[interleaver_pattern[i]]; d_deinterleaved[i] = rx_bits[interleaver_pattern[i]];
} }
} }
bool bool frame_equalizer_impl::parse_signal(uint8_t* decoded_bits)
frame_equalizer_impl::parse_signal(uint8_t *decoded_bits) { {
int r = 0; int r = 0;
d_frame_bytes = 0; d_frame_bytes = 0;
@@ -339,19 +354,16 @@ frame_equalizer_impl::parse_signal(uint8_t *decoded_bits) {
return false; return false;
} }
mylog(boost::format("encoding: %1% - length: %2% - symbols: %3%") mylog(boost::format("encoding: %1% - length: %2% - symbols: %3%") % d_frame_encoding %
% d_frame_encoding % d_frame_bytes % d_frame_symbols); d_frame_bytes % d_frame_symbols);
return true; return true;
} }
const int const int frame_equalizer_impl::interleaver_pattern[48] = {
frame_equalizer_impl::interleaver_pattern[48] = { 0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45,
0, 3, 6, 9,12,15,18,21, 1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 40, 43, 46,
24,27,30,33,36,39,42,45, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47
1, 4, 7,10,13,16,19,22, };
25,28,31,34,37,40,43,46,
2, 5, 8,11,14,17,20,23,
26,29,32,35,38,41,44,47};
} /* namespace ieee802_11 */ } /* namespace ieee802_11 */
} /* namespace gr */ } /* namespace gr */
+2 -4
View File
@@ -18,10 +18,10 @@
#ifndef INCLUDED_IEEE802_11_FRAME_EQUALIZER_IMPL_H #ifndef INCLUDED_IEEE802_11_FRAME_EQUALIZER_IMPL_H
#define INCLUDED_IEEE802_11_FRAME_EQUALIZER_IMPL_H #define INCLUDED_IEEE802_11_FRAME_EQUALIZER_IMPL_H
#include <ieee802_11/frame_equalizer.h>
#include <ieee802_11/constellations.h>
#include "equalizer/base.h" #include "equalizer/base.h"
#include "viterbi_decoder/viterbi_decoder.h" #include "viterbi_decoder/viterbi_decoder.h"
#include <ieee802_11/constellations.h>
#include <ieee802_11/frame_equalizer.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -44,8 +44,6 @@ public:
gr_vector_void_star& output_items); gr_vector_void_star& output_items);
private: private:
bool parse_signal(uint8_t* signal); bool parse_signal(uint8_t* signal);
bool decode_signal_field(uint8_t* rx_bits); bool decode_signal_field(uint8_t* rx_bits);
void deinterleave(uint8_t* rx_bits); void deinterleave(uint8_t* rx_bits);
+33 -21
View File
@@ -16,8 +16,8 @@
*/ */
#include <ieee802_11/mac.h> #include <ieee802_11/mac.h>
#include <gnuradio/io_signature.h>
#include <gnuradio/block_detail.h> #include <gnuradio/block_detail.h>
#include <gnuradio/io_signature.h>
#include "utils.h" #include "utils.h"
@@ -34,28 +34,34 @@
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
class mac_impl : public mac { class mac_impl : public mac
{
public: public:
mac_impl(std::vector<uint8_t> src_mac,
mac_impl(std::vector<uint8_t> src_mac, std::vector<uint8_t> dst_mac, std::vector<uint8_t> bss_mac) : std::vector<uint8_t> dst_mac,
block("mac", std::vector<uint8_t> bss_mac)
gr::io_signature::make(0, 0, 0), : block("mac", gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0)),
gr::io_signature::make(0, 0, 0)), d_seq_nr(0)
d_seq_nr(0) { {
message_port_register_out(pmt::mp("phy out")); message_port_register_out(pmt::mp("phy out"));
message_port_register_out(pmt::mp("app out")); message_port_register_out(pmt::mp("app out"));
message_port_register_in(pmt::mp("app in")); message_port_register_in(pmt::mp("app in"));
set_msg_handler(pmt::mp("app in"), boost::bind(&mac_impl::app_in, this, boost::placeholders::_1)); set_msg_handler(pmt::mp("app in"),
boost::bind(&mac_impl::app_in, this, boost::placeholders::_1));
message_port_register_in(pmt::mp("phy in")); message_port_register_in(pmt::mp("phy in"));
set_msg_handler(pmt::mp("phy in"), boost::bind(&mac_impl::phy_in, this, boost::placeholders::_1)); set_msg_handler(pmt::mp("phy in"),
boost::bind(&mac_impl::phy_in, this, boost::placeholders::_1));
if(!check_mac(src_mac)) throw std::invalid_argument("wrong mac address size"); if (!check_mac(src_mac))
if(!check_mac(dst_mac)) throw std::invalid_argument("wrong mac address size"); throw std::invalid_argument("wrong mac address size");
if(!check_mac(bss_mac)) throw std::invalid_argument("wrong mac address size"); if (!check_mac(dst_mac))
throw std::invalid_argument("wrong mac address size");
if (!check_mac(bss_mac))
throw std::invalid_argument("wrong mac address size");
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
d_src_mac[i] = src_mac[i]; d_src_mac[i] = src_mac[i];
@@ -64,7 +70,8 @@ mac_impl(std::vector<uint8_t> src_mac, std::vector<uint8_t> dst_mac, std::vector
} }
} }
void phy_in (pmt::pmt_t msg) { void phy_in(pmt::pmt_t msg)
{
// this must be a pair // this must be a pair
if (!pmt::is_blob(pmt::cdr(msg))) { if (!pmt::is_blob(pmt::cdr(msg))) {
throw std::runtime_error("PMT must be blob"); throw std::runtime_error("PMT must be blob");
@@ -80,7 +87,8 @@ void phy_in (pmt::pmt_t msg) {
message_port_pub(pmt::mp("app out"), pmt::cons(pmt::car(msg), msdu)); message_port_pub(pmt::mp("app out"), pmt::cons(pmt::car(msg), msdu));
} }
void app_in (pmt::pmt_t msg) { void app_in(pmt::pmt_t msg)
{
size_t msg_len; size_t msg_len;
const char* msdu; const char* msdu;
@@ -121,7 +129,8 @@ void app_in (pmt::pmt_t msg) {
message_port_pub(pmt::mp("phy out"), pmt::cons(dict, mac)); message_port_pub(pmt::mp("phy out"), pmt::cons(dict, mac));
} }
void generate_mac_data_frame(const char *msdu, int msdu_size, int *psdu_size) { void generate_mac_data_frame(const char* msdu, int msdu_size, int* psdu_size)
{
// mac header // mac header
mac_header header; mac_header header;
@@ -158,8 +167,10 @@ void generate_mac_data_frame(const char *msdu, int msdu_size, int *psdu_size) {
memcpy(d_psdu + msdu_size + 24, &fcs, sizeof(uint32_t)); memcpy(d_psdu + msdu_size + 24, &fcs, sizeof(uint32_t));
} }
bool check_mac(std::vector<uint8_t> mac) { bool check_mac(std::vector<uint8_t> mac)
if(mac.size() != 6) return false; {
if (mac.size() != 6)
return false;
return true; return true;
} }
@@ -171,8 +182,9 @@ private:
uint8_t d_psdu[MAX_PSDU_SIZE]; uint8_t d_psdu[MAX_PSDU_SIZE];
}; };
mac::sptr mac::sptr mac::make(std::vector<uint8_t> src_mac,
mac::make(std::vector<uint8_t> src_mac, std::vector<uint8_t> dst_mac, std::vector<uint8_t> bss_mac) { std::vector<uint8_t> dst_mac,
std::vector<uint8_t> bss_mac)
{
return gnuradio::get_initial_sptr(new mac_impl(src_mac, dst_mac, bss_mac)); return gnuradio::get_initial_sptr(new mac_impl(src_mac, dst_mac, bss_mac));
} }
+31 -25
View File
@@ -14,37 +14,37 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <ieee802_11/mapper.h>
#include "utils.h" #include "utils.h"
#include <gnuradio/io_signature.h> #include <gnuradio/io_signature.h>
#include <ieee802_11/mapper.h>
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
class mapper_impl : public mapper { class mapper_impl : public mapper
{
public: public:
static const int DATA_CARRIERS = 48; static const int DATA_CARRIERS = 48;
mapper_impl(Encoding e, bool debug) : mapper_impl(Encoding e, bool debug)
block ("mapper", : block("mapper",
gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0),
gr::io_signature::make(1, 1, sizeof(char))), gr::io_signature::make(1, 1, sizeof(char))),
d_symbols_offset(0), d_symbols_offset(0),
d_symbols(NULL), d_symbols(NULL),
d_debug(debug), d_debug(debug),
d_scrambler(1), d_scrambler(1),
d_ofdm(e) { d_ofdm(e)
{
message_port_register_in(pmt::mp("in")); message_port_register_in(pmt::mp("in"));
set_encoding(e); set_encoding(e);
} }
~mapper_impl() { ~mapper_impl() { free(d_symbols); }
free(d_symbols);
}
void print_message(const char *msg, size_t len) { void print_message(const char* msg, size_t len)
{
dout << std::hex << "MAPPER input symbols" << std::endl dout << std::hex << "MAPPER input symbols" << std::endl
@@ -58,13 +58,15 @@ void print_message(const char *msg, size_t len) {
} }
int general_work(int noutput, gr_vector_int& ninput_items, int general_work(int noutput,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items, gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items ) { gr_vector_void_star& output_items)
{
unsigned char* out = (unsigned char*)output_items[0]; unsigned char* out = (unsigned char*)output_items[0];
dout << "MAPPER called offset: " << d_symbols_offset << dout << "MAPPER called offset: " << d_symbols_offset
" length: " << d_symbols_len << std::endl; << " length: " << d_symbols_len << std::endl;
while (!d_symbols_offset) { while (!d_symbols_offset) {
pmt::pmt_t msg(delete_head_nowait(pmt::intern("in"))); pmt::pmt_t msg(delete_head_nowait(pmt::intern("in")));
@@ -78,12 +80,14 @@ int general_work(int noutput, gr_vector_int& ninput_items,
gr::thread::scoped_lock lock(d_mutex); gr::thread::scoped_lock lock(d_mutex);
int psdu_length = pmt::blob_length(pmt::cdr(msg)); int psdu_length = pmt::blob_length(pmt::cdr(msg));
const char *psdu = static_cast<const char*>(pmt::blob_data(pmt::cdr(msg))); const char* psdu =
static_cast<const char*>(pmt::blob_data(pmt::cdr(msg)));
// ############ INSERT MAC STUFF // ############ INSERT MAC STUFF
frame_param frame(d_ofdm, psdu_length); frame_param frame(d_ofdm, psdu_length);
if (frame.n_sym > MAX_SYM) { if (frame.n_sym > MAX_SYM) {
std::cout << "packet too large, maximum number of symbols is " << MAX_SYM << std::endl; std::cout << "packet too large, maximum number of symbols is "
<< MAX_SYM << std::endl;
return 0; return 0;
} }
@@ -92,8 +96,10 @@ int general_work(int noutput, gr_vector_int& ninput_items,
char* scrambled_data = (char*)calloc(frame.n_data_bits, sizeof(char)); char* scrambled_data = (char*)calloc(frame.n_data_bits, sizeof(char));
char* encoded_data = (char*)calloc(frame.n_data_bits * 2, sizeof(char)); char* encoded_data = (char*)calloc(frame.n_data_bits * 2, sizeof(char));
char* punctured_data = (char*)calloc(frame.n_encoded_bits, sizeof(char)); char* punctured_data = (char*)calloc(frame.n_encoded_bits, sizeof(char));
char *interleaved_data = (char*)calloc(frame.n_encoded_bits, sizeof(char)); char* interleaved_data =
char *symbols = (char*)calloc((frame.n_encoded_bits / d_ofdm.n_bpsc), sizeof(char)); (char*)calloc(frame.n_encoded_bits, sizeof(char));
char* symbols =
(char*)calloc((frame.n_encoded_bits / d_ofdm.n_bpsc), sizeof(char));
// generate the WIFI data field, adding service field and pad bits // generate the WIFI data field, adding service field and pad bits
generate_bits(psdu, data_bits, frame); generate_bits(psdu, data_bits, frame);
@@ -131,12 +137,11 @@ int general_work(int noutput, gr_vector_int& ninput_items,
add_item_tag(0, nitems_written(0), key, value, srcid); add_item_tag(0, nitems_written(0), key, value, srcid);
pmt::pmt_t psdu_bytes = pmt::from_long(psdu_length); pmt::pmt_t psdu_bytes = pmt::from_long(psdu_length);
add_item_tag(0, nitems_written(0), pmt::mp("psdu_len"), add_item_tag(
psdu_bytes, srcid); 0, nitems_written(0), pmt::mp("psdu_len"), psdu_bytes, srcid);
pmt::pmt_t encoding = pmt::from_long(d_ofdm.encoding); pmt::pmt_t encoding = pmt::from_long(d_ofdm.encoding);
add_item_tag(0, nitems_written(0), pmt::mp("encoding"), add_item_tag(0, nitems_written(0), pmt::mp("encoding"), encoding, srcid);
encoding, srcid);
free(data_bits); free(data_bits);
@@ -163,7 +168,8 @@ int general_work(int noutput, gr_vector_int& ninput_items,
return i; return i;
} }
void set_encoding(Encoding encoding) { void set_encoding(Encoding encoding)
{
std::cout << "MAPPER: encoding: " << encoding << std::endl; std::cout << "MAPPER: encoding: " << encoding << std::endl;
gr::thread::scoped_lock lock(d_mutex); gr::thread::scoped_lock lock(d_mutex);
@@ -181,7 +187,7 @@ private:
gr::thread::mutex d_mutex; gr::thread::mutex d_mutex;
}; };
mapper::sptr mapper::sptr mapper::make(Encoding mcs, bool debug)
mapper::make(Encoding mcs, bool debug) { {
return gnuradio::get_initial_sptr(new mapper_impl(mcs, debug)); return gnuradio::get_initial_sptr(new mapper_impl(mcs, debug));
} }
+62 -38
View File
@@ -14,37 +14,40 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <ieee802_11/parse_mac.h>
#include "utils.h" #include "utils.h"
#include <ieee802_11/parse_mac.h>
#include <gnuradio/io_signature.h>
#include <gnuradio/block_detail.h> #include <gnuradio/block_detail.h>
#include <gnuradio/io_signature.h>
#include <string> #include <string>
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
class parse_mac_impl : public parse_mac { class parse_mac_impl : public parse_mac
{
public: public:
parse_mac_impl(bool log, bool debug)
parse_mac_impl(bool log, bool debug) : : block("parse_mac",
block("parse_mac",
gr::io_signature::make(0, 0, 0), gr::io_signature::make(0, 0, 0),
gr::io_signature::make(0, 0, 0)), gr::io_signature::make(0, 0, 0)),
d_log(log), d_last_seq_no(-1), d_log(log),
d_debug(debug) { d_last_seq_no(-1),
d_debug(debug)
{
message_port_register_in(pmt::mp("in")); message_port_register_in(pmt::mp("in"));
set_msg_handler(pmt::mp("in"), boost::bind(&parse_mac_impl::parse, this, boost::placeholders::_1)); set_msg_handler(
pmt::mp("in"),
boost::bind(&parse_mac_impl::parse, this, boost::placeholders::_1));
message_port_register_out(pmt::mp("out")); message_port_register_out(pmt::mp("out"));
} }
~parse_mac_impl() { ~parse_mac_impl() {}
} void parse(pmt::pmt_t pdu)
{
void parse(pmt::pmt_t pdu) {
if (pmt::is_eof_object(pdu)) { if (pmt::is_eof_object(pdu)) {
detail().get()->set_done(true); detail().get()->set_done(true);
@@ -71,8 +74,10 @@ void parse(pmt::pmt_t pdu) {
d_meta = pmt::dict_add(d_meta, pmt::mp("Duration"), pmt::mp(h->duration)); d_meta = pmt::dict_add(d_meta, pmt::mp("Duration"), pmt::mp(h->duration));
#define HEX(a) std::hex << std::setfill('0') << std::setw(2) << int(a) << std::dec #define HEX(a) std::hex << std::setfill('0') << std::setw(2) << int(a) << std::dec
dout << "duration: " << HEX(h->duration >> 8) << " " << HEX(h->duration & 0xff) << std::endl; dout << "duration: " << HEX(h->duration >> 8) << " " << HEX(h->duration & 0xff)
dout << "frame control: " << HEX(h->frame_control >> 8) << " " << HEX(h->frame_control & 0xff); << std::endl;
dout << "frame control: " << HEX(h->frame_control >> 8) << " "
<< HEX(h->frame_control & 0xff);
switch ((h->frame_control >> 2) & 3) { switch ((h->frame_control >> 2) & 3) {
@@ -112,7 +117,8 @@ void parse(pmt::pmt_t pdu) {
message_port_pub(pmt::mp("out"), pmt::cons(d_meta, d_msg)); message_port_pub(pmt::mp("out"), pmt::cons(d_meta, d_msg));
} }
void parse_management(char *buf, int length) { void parse_management(char* buf, int length)
{
mac_header* h = (mac_header*)buf; mac_header* h = (mac_header*)buf;
if (length < 24) { if (length < 24) {
@@ -123,19 +129,23 @@ void parse_management(char *buf, int length) {
dout << "Subtype: "; dout << "Subtype: ";
switch (((h->frame_control) >> 4) & 0xf) { switch (((h->frame_control) >> 4) & 0xf) {
case 0: case 0:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Association Request")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Association Request"));
dout << "Association Request"; dout << "Association Request";
break; break;
case 1: case 1:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Association Response")); d_meta = pmt::dict_add(
d_meta, pmt::mp("Subtype"), pmt::mp("Association Response"));
dout << "Association Response"; dout << "Association Response";
break; break;
case 2: case 2:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Reassociation Request")); d_meta = pmt::dict_add(
d_meta, pmt::mp("Subtype"), pmt::mp("Reassociation Request"));
dout << "Reassociation Request"; dout << "Reassociation Request";
break; break;
case 3: case 3:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Reassociation Response")); d_meta = pmt::dict_add(
d_meta, pmt::mp("Subtype"), pmt::mp("Reassociation Response"));
dout << "Reassociation Response"; dout << "Reassociation Response";
break; break;
case 4: case 4:
@@ -147,7 +157,8 @@ void parse_management(char *buf, int length) {
dout << "Probe Response"; dout << "Probe Response";
break; break;
case 6: case 6:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Timing Advertisement")); d_meta = pmt::dict_add(
d_meta, pmt::mp("Subtype"), pmt::mp("Timing Advertisement"));
dout << "Timing Advertisement"; dout << "Timing Advertisement";
break; break;
case 7: case 7:
@@ -183,7 +194,8 @@ void parse_management(char *buf, int length) {
dout << "Authentication"; dout << "Authentication";
break; break;
case 12: case 12:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Deauthentication")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Deauthentication"));
dout << "Deauthentication"; dout << "Deauthentication";
break; break;
case 13: case 13:
@@ -221,7 +233,8 @@ void parse_management(char *buf, int length) {
} }
void parse_data(char *buf, int length) { void parse_data(char* buf, int length)
{
mac_header* h = (mac_header*)buf; mac_header* h = (mac_header*)buf;
if (length < 24) { if (length < 24) {
dout << "too short for a data frame" << std::endl; dout << "too short for a data frame" << std::endl;
@@ -243,7 +256,8 @@ void parse_data(char *buf, int length) {
dout << "Data + CR-Poll"; dout << "Data + CR-Poll";
break; break;
case 3: case 3:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Data + CF-ACK + CF-Poll")); d_meta = pmt::dict_add(
d_meta, pmt::mp("Subtype"), pmt::mp("Data + CF-ACK + CF-Poll"));
dout << "Data + CF-ACK + CF-Poll"; dout << "Data + CF-ACK + CF-Poll";
break; break;
case 4: case 4:
@@ -259,7 +273,8 @@ void parse_data(char *buf, int length) {
dout << "CF-Poll"; dout << "CF-Poll";
break; break;
case 7: case 7:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-ACK + CF-Poll")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-ACK + CF-Poll"));
dout << "CF-ACK + CF-Poll"; dout << "CF-ACK + CF-Poll";
break; break;
case 8: case 8:
@@ -267,15 +282,18 @@ void parse_data(char *buf, int length) {
dout << "QoS Data"; dout << "QoS Data";
break; break;
case 9: case 9:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-ACK")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-ACK"));
dout << "QoS Data + CF-ACK"; dout << "QoS Data + CF-ACK";
break; break;
case 10: case 10:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-Poll")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-Poll"));
dout << "QoS Data + CF-Poll"; dout << "QoS Data + CF-Poll";
break; break;
case 11: case 11:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-ACK + CF-Poll")); d_meta = pmt::dict_add(
d_meta, pmt::mp("Subtype"), pmt::mp("QoS Data + CF-ACK + CF-Poll"));
dout << "QoS Data + CF-ACK + CF-Poll"; dout << "QoS Data + CF-ACK + CF-Poll";
break; break;
case 12: case 12:
@@ -291,7 +309,8 @@ void parse_data(char *buf, int length) {
dout << "QoS CF-Poll"; dout << "QoS CF-Poll";
break; break;
case 15: case 15:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("QoS CF-ACK + CF-Poll")); d_meta = pmt::dict_add(
d_meta, pmt::mp("Subtype"), pmt::mp("QoS CF-ACK + CF-Poll"));
dout << "QoS CF-ACK + CF-Poll"; dout << "QoS CF-ACK + CF-Poll";
break; break;
default: default:
@@ -331,17 +350,20 @@ void parse_data(char *buf, int length) {
d_last_seq_no = seq_no; d_last_seq_no = seq_no;
} }
void parse_control(char *buf, int length) { void parse_control(char* buf, int length)
{
mac_header* h = (mac_header*)buf; mac_header* h = (mac_header*)buf;
dout << "Subtype: "; dout << "Subtype: ";
switch (((h->frame_control) >> 4) & 0xf) { switch (((h->frame_control) >> 4) & 0xf) {
case 7: case 7:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Control Wrapper")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Control Wrapper"));
dout << "Control Wrapper"; dout << "Control Wrapper";
break; break;
case 8: case 8:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Block ACK Request")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("Block ACK Request"));
dout << "Block ACK Request"; dout << "Block ACK Request";
break; break;
case 9: case 9:
@@ -369,7 +391,8 @@ void parse_control(char *buf, int length) {
dout << "CF-End"; dout << "CF-End";
break; break;
case 15: case 15:
d_meta = pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-End + CF-ACK")); d_meta =
pmt::dict_add(d_meta, pmt::mp("Subtype"), pmt::mp("CF-End + CF-ACK"));
dout << "CF-End + CF-ACK"; dout << "CF-End + CF-ACK";
break; break;
default: default:
@@ -389,7 +412,8 @@ void parse_control(char *buf, int length) {
dout << "TA: " << address << std::endl; dout << "TA: " << address << std::endl;
} }
std::string format_mac_address(uint8_t *addr) { std::string format_mac_address(uint8_t* addr)
{
std::stringstream str; std::stringstream str;
str << std::setfill('0') << std::hex << std::setw(2) << (int)addr[0]; str << std::setfill('0') << std::hex << std::setw(2) << (int)addr[0];
@@ -401,7 +425,8 @@ std::string format_mac_address(uint8_t *addr) {
return str.str(); return str.str();
} }
void print_ascii(char* buf, int length) { void print_ascii(char* buf, int length)
{
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
if ((buf[i] > 31) && (buf[i] < 127)) { if ((buf[i] > 31) && (buf[i] < 127)) {
@@ -421,8 +446,7 @@ private:
pmt::pmt_t d_msg; pmt::pmt_t d_msg;
}; };
parse_mac::sptr parse_mac::sptr parse_mac::make(bool log, bool debug)
parse_mac::make(bool log, bool debug) { {
return gnuradio::get_initial_sptr(new parse_mac_impl(log, debug)); return gnuradio::get_initial_sptr(new parse_mac_impl(log, debug));
} }
+12 -9
View File
@@ -21,8 +21,8 @@
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
signal_field::sptr signal_field::sptr signal_field::make()
signal_field::make() { {
return signal_field::sptr(new signal_field_impl()); return signal_field::sptr(new signal_field_impl());
} }
@@ -35,12 +35,13 @@ signal_field_impl::signal_field_impl() : packet_header_default(48, "packet_len")
signal_field_impl::~signal_field_impl() {} signal_field_impl::~signal_field_impl() {}
int signal_field_impl::get_bit(int b, int i) { int signal_field_impl::get_bit(int b, int i) { return (b & (1 << i) ? 1 : 0); }
return (b & (1 << i) ? 1 : 0);
}
void signal_field_impl::generate_signal_field(char *out, frame_param &frame, ofdm_param &ofdm) { void signal_field_impl::generate_signal_field(char* out,
frame_param& frame,
ofdm_param& ofdm)
{
// data bits of the signal header // data bits of the signal header
char* signal_header = (char*)malloc(sizeof(char) * 24); char* signal_header = (char*)malloc(sizeof(char) * 24);
@@ -100,7 +101,9 @@ void signal_field_impl::generate_signal_field(char *out, frame_param &frame, ofd
free(interleaved_signal_header); free(interleaved_signal_header);
} }
bool signal_field_impl::header_formatter(long packet_len, unsigned char *out, const std::vector<tag_t> &tags) bool signal_field_impl::header_formatter(long packet_len,
unsigned char* out,
const std::vector<tag_t>& tags)
{ {
bool encoding_found = false; bool encoding_found = false;
@@ -131,8 +134,8 @@ bool signal_field_impl::header_formatter(long packet_len, unsigned char *out, co
return true; return true;
} }
bool signal_field_impl::header_parser( bool signal_field_impl::header_parser(const unsigned char* in, std::vector<tag_t>& tags)
const unsigned char *in, std::vector<tag_t> &tags) { {
throw std::runtime_error("not implemented yet"); throw std::runtime_error("not implemented yet");
return false; return false;
+5 -6
View File
@@ -18,8 +18,8 @@
#ifndef INCLUDED_IEEE802_11_SIGNAL_FIELD_IMPL_H #ifndef INCLUDED_IEEE802_11_SIGNAL_FIELD_IMPL_H
#define INCLUDED_IEEE802_11_SIGNAL_FIELD_IMPL_H #define INCLUDED_IEEE802_11_SIGNAL_FIELD_IMPL_H
#include <ieee802_11/signal_field.h>
#include "utils.h" #include "utils.h"
#include <ieee802_11/signal_field.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -30,11 +30,11 @@ public:
signal_field_impl(); signal_field_impl();
~signal_field_impl(); ~signal_field_impl();
bool header_formatter(long packet_len, unsigned char *out, bool
const std::vector<tag_t> &tags); header_formatter(long packet_len, unsigned char* out, const std::vector<tag_t>& tags);
bool header_parser(const unsigned char* header, std::vector<tag_t>& tags);
bool header_parser(const unsigned char *header,
std::vector<tag_t> &tags);
private: private:
int get_bit(int b, int i); int get_bit(int b, int i);
void generate_signal_field(char* out, frame_param& frame, ofdm_param& ofdm); void generate_signal_field(char* out, frame_param& frame, ofdm_param& ofdm);
@@ -44,4 +44,3 @@ private:
} // namespace gr } // namespace gr
#endif /* INCLUDED_IEEE802_11_SIGNAL_FIELD_IMPL_H */ #endif /* INCLUDED_IEEE802_11_SIGNAL_FIELD_IMPL_H */
+61 -37
View File
@@ -14,11 +14,11 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <ieee802_11/sync_long.h>
#include "utils.h" #include "utils.h"
#include <gnuradio/io_signature.h>
#include <gnuradio/filter/fir_filter.h>
#include <gnuradio/fft/fft.h> #include <gnuradio/fft/fft.h>
#include <gnuradio/filter/fir_filter.h>
#include <gnuradio/io_signature.h>
#include <ieee802_11/sync_long.h>
#include <list> #include <list>
#include <tuple> #include <tuple>
@@ -27,14 +27,18 @@ using namespace gr::ieee802_11;
using namespace std; using namespace std;
bool compare_abs(const std::pair<gr_complex, int>& first, const std::pair<gr_complex, int>& second) { bool compare_abs(const std::pair<gr_complex, int>& first,
const std::pair<gr_complex, int>& second)
{
return abs(get<0>(first)) > abs(get<0>(second)); return abs(get<0>(first)) > abs(get<0>(second));
} }
class sync_long_impl : public sync_long { class sync_long_impl : public sync_long
{
public: public:
sync_long_impl(unsigned int sync_length, bool log, bool debug) : block("sync_long", sync_long_impl(unsigned int sync_length, bool log, bool debug)
: block("sync_long",
gr::io_signature::make2(2, 2, sizeof(gr_complex), sizeof(gr_complex)), gr::io_signature::make2(2, 2, sizeof(gr_complex), sizeof(gr_complex)),
gr::io_signature::make(1, 1, sizeof(gr_complex))), gr::io_signature::make(1, 1, sizeof(gr_complex))),
d_fir(gr::filter::kernel::fir_filter_ccc(1, LONG)), d_fir(gr::filter::kernel::fir_filter_ccc(1, LONG)),
@@ -42,27 +46,27 @@ sync_long_impl(unsigned int sync_length, bool log, bool debug) : block("sync_lon
d_debug(debug), d_debug(debug),
d_offset(0), d_offset(0),
d_state(SYNC), d_state(SYNC),
SYNC_LENGTH(sync_length) { SYNC_LENGTH(sync_length)
{
set_tag_propagation_policy(block::TPP_DONT); set_tag_propagation_policy(block::TPP_DONT);
d_correlation = gr::fft::malloc_complex(8192); d_correlation = gr::fft::malloc_complex(8192);
} }
~sync_long_impl(){ ~sync_long_impl() { gr::fft::free(d_correlation); }
gr::fft::free(d_correlation);
}
int general_work (int noutput, gr_vector_int& ninput_items, int general_work(int noutput,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items, gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items) { gr_vector_void_star& output_items)
{
const gr_complex* in = (const gr_complex*)input_items[0]; const gr_complex* in = (const gr_complex*)input_items[0];
const gr_complex* in_delayed = (const gr_complex*)input_items[1]; const gr_complex* in_delayed = (const gr_complex*)input_items[1];
gr_complex* out = (gr_complex*)output_items[0]; gr_complex* out = (gr_complex*)output_items[0];
dout << "LONG ninput[0] " << ninput_items[0] << " ninput[1] " << dout << "LONG ninput[0] " << ninput_items[0] << " ninput[1] " << ninput_items[1]
ninput_items[1] << " noutput " << noutput << << " noutput " << noutput << " state " << d_state << std::endl;
" state " << d_state << std::endl;
int ninput = std::min(std::min(ninput_items[0], ninput_items[1]), 8192); int ninput = std::min(std::min(ninput_items[0], ninput_items[1]), 8192);
@@ -93,7 +97,8 @@ int general_work (int noutput, gr_vector_int& ninput_items,
switch (d_state) { switch (d_state) {
case SYNC: case SYNC:
d_fir.filterN(d_correlation, in, std::min(SYNC_LENGTH, std::max(ninput - 63, 0))); d_fir.filterN(
d_correlation, in, std::min(SYNC_LENGTH, std::max(ninput - 63, 0)));
while (i + 63 < ninput) { while (i + 63 < ninput) {
@@ -121,7 +126,8 @@ int general_work (int noutput, gr_vector_int& ninput_items,
int rel = d_offset - d_frame_start; int rel = d_offset - d_frame_start;
if (!rel) { if (!rel) {
add_item_tag(0, nitems_written(0), add_item_tag(0,
nitems_written(0),
pmt::string_to_symbol("wifi_start"), pmt::string_to_symbol("wifi_start"),
pmt::from_double(d_freq_offset_short - d_freq_offset), pmt::from_double(d_freq_offset_short - d_freq_offset),
pmt::string_to_symbol(name())); pmt::string_to_symbol(name()));
@@ -162,7 +168,8 @@ int general_work (int noutput, gr_vector_int& ninput_items,
return o; return o;
} }
void forecast (int noutput_items, gr_vector_int &ninput_items_required) { void forecast(int noutput_items, gr_vector_int& ninput_items_required)
{
// in sync state we need at least a symbol to correlate // in sync state we need at least a symbol to correlate
// with the pattern // with the pattern
@@ -176,7 +183,8 @@ void forecast (int noutput_items, gr_vector_int &ninput_items_required) {
} }
} }
void search_frame_start() { void search_frame_start()
{
// sort list (highest correlation first) // sort list (highest correlation first)
assert(d_cor.size() == SYNC_LENGTH); assert(d_cor.size() == SYNC_LENGTH);
@@ -238,28 +246,44 @@ private:
static const std::vector<gr_complex> LONG; static const std::vector<gr_complex> LONG;
}; };
sync_long::sptr sync_long::sptr sync_long::make(unsigned int sync_length, bool log, bool debug)
sync_long::make(unsigned int sync_length, bool log, bool debug) { {
return gnuradio::get_initial_sptr(new sync_long_impl(sync_length, log, debug)); return gnuradio::get_initial_sptr(new sync_long_impl(sync_length, log, debug));
} }
const std::vector<gr_complex> sync_long_impl::LONG = { const std::vector<gr_complex> sync_long_impl::LONG = {
gr_complex(-0.0455, -1.0679), gr_complex( 0.3528, -0.9865), gr_complex( 0.8594, 0.7348), gr_complex( 0.1874, 0.2475), gr_complex(-0.0455, -1.0679), gr_complex(0.3528, -0.9865),
gr_complex( 0.5309, -0.7784), gr_complex(-1.0218, -0.4897), gr_complex(-0.3401, -0.9423), gr_complex( 0.8657, -0.2298), gr_complex(0.8594, 0.7348), gr_complex(0.1874, 0.2475),
gr_complex( 0.4734, 0.0362), gr_complex( 0.0088, -1.0207), gr_complex(-1.2142, -0.4205), gr_complex( 0.2172, -0.5195), gr_complex(0.5309, -0.7784), gr_complex(-1.0218, -0.4897),
gr_complex( 0.5207, -0.1326), gr_complex(-0.1995, 1.4259), gr_complex( 1.0583, -0.0363), gr_complex( 0.5547, -0.5547), gr_complex(-0.3401, -0.9423), gr_complex(0.8657, -0.2298),
gr_complex( 0.3277, 0.8728), gr_complex(-0.5077, 0.3488), gr_complex(-1.1650, 0.5789), gr_complex( 0.7297, 0.8197), gr_complex(0.4734, 0.0362), gr_complex(0.0088, -1.0207),
gr_complex( 0.6173, 0.1253), gr_complex(-0.5353, 0.7214), gr_complex(-0.5011, -0.1935), gr_complex(-0.3110, -1.3392), gr_complex(-1.2142, -0.4205), gr_complex(0.2172, -0.5195),
gr_complex(-1.0818, -0.1470), gr_complex(-1.1300, -0.1820), gr_complex( 0.6663, -0.6571), gr_complex(-0.0249, 0.4773), gr_complex(0.5207, -0.1326), gr_complex(-0.1995, 1.4259),
gr_complex(-0.8155, 1.0218), gr_complex( 0.8140, 0.9396), gr_complex( 0.1090, 0.8662), gr_complex(-1.3868, -0.0000), gr_complex(1.0583, -0.0363), gr_complex(0.5547, -0.5547),
gr_complex( 0.1090, -0.8662), gr_complex( 0.8140, -0.9396), gr_complex(-0.8155, -1.0218), gr_complex(-0.0249, -0.4773), gr_complex(0.3277, 0.8728), gr_complex(-0.5077, 0.3488),
gr_complex( 0.6663, 0.6571), gr_complex(-1.1300, 0.1820), gr_complex(-1.0818, 0.1470), gr_complex(-0.3110, 1.3392), gr_complex(-1.1650, 0.5789), gr_complex(0.7297, 0.8197),
gr_complex(-0.5011, 0.1935), gr_complex(-0.5353, -0.7214), gr_complex( 0.6173, -0.1253), gr_complex( 0.7297, -0.8197), gr_complex(0.6173, 0.1253), gr_complex(-0.5353, 0.7214),
gr_complex(-1.1650, -0.5789), gr_complex(-0.5077, -0.3488), gr_complex( 0.3277, -0.8728), gr_complex( 0.5547, 0.5547), gr_complex(-0.5011, -0.1935), gr_complex(-0.3110, -1.3392),
gr_complex( 1.0583, 0.0363), gr_complex(-0.1995, -1.4259), gr_complex( 0.5207, 0.1326), gr_complex( 0.2172, 0.5195), gr_complex(-1.0818, -0.1470), gr_complex(-1.1300, -0.1820),
gr_complex(-1.2142, 0.4205), gr_complex( 0.0088, 1.0207), gr_complex( 0.4734, -0.0362), gr_complex( 0.8657, 0.2298), gr_complex(0.6663, -0.6571), gr_complex(-0.0249, 0.4773),
gr_complex(-0.3401, 0.9423), gr_complex(-1.0218, 0.4897), gr_complex( 0.5309, 0.7784), gr_complex( 0.1874, -0.2475), gr_complex(-0.8155, 1.0218), gr_complex(0.8140, 0.9396),
gr_complex( 0.8594, -0.7348), gr_complex( 0.3528, 0.9865), gr_complex(-0.0455, 1.0679), gr_complex( 1.3868, -0.0000), gr_complex(0.1090, 0.8662), gr_complex(-1.3868, -0.0000),
gr_complex(0.1090, -0.8662), gr_complex(0.8140, -0.9396),
gr_complex(-0.8155, -1.0218), gr_complex(-0.0249, -0.4773),
gr_complex(0.6663, 0.6571), gr_complex(-1.1300, 0.1820),
gr_complex(-1.0818, 0.1470), gr_complex(-0.3110, 1.3392),
gr_complex(-0.5011, 0.1935), gr_complex(-0.5353, -0.7214),
gr_complex(0.6173, -0.1253), gr_complex(0.7297, -0.8197),
gr_complex(-1.1650, -0.5789), gr_complex(-0.5077, -0.3488),
gr_complex(0.3277, -0.8728), gr_complex(0.5547, 0.5547),
gr_complex(1.0583, 0.0363), gr_complex(-0.1995, -1.4259),
gr_complex(0.5207, 0.1326), gr_complex(0.2172, 0.5195),
gr_complex(-1.2142, 0.4205), gr_complex(0.0088, 1.0207),
gr_complex(0.4734, -0.0362), gr_complex(0.8657, 0.2298),
gr_complex(-0.3401, 0.9423), gr_complex(-1.0218, 0.4897),
gr_complex(0.5309, 0.7784), gr_complex(0.1874, -0.2475),
gr_complex(0.8594, -0.7348), gr_complex(0.3528, 0.9865),
gr_complex(-0.0455, 1.0679), gr_complex(1.3868, -0.0000),
}; };
+26 -15
View File
@@ -14,9 +14,9 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <ieee802_11/sync_short.h>
#include <gnuradio/io_signature.h>
#include "utils.h" #include "utils.h"
#include <gnuradio/io_signature.h>
#include <ieee802_11/sync_short.h>
#include <iostream> #include <iostream>
@@ -25,12 +25,14 @@ using namespace gr::ieee802_11;
static const int MIN_GAP = 480; static const int MIN_GAP = 480;
static const int MAX_SAMPLES = 540 * 80; static const int MAX_SAMPLES = 540 * 80;
class sync_short_impl : public sync_short { class sync_short_impl : public sync_short
{
public: public:
sync_short_impl(double threshold, unsigned int min_plateau, bool log, bool debug) : sync_short_impl(double threshold, unsigned int min_plateau, bool log, bool debug)
block("sync_short", : block("sync_short",
gr::io_signature::make3(3, 3, sizeof(gr_complex), sizeof(gr_complex), sizeof(float)), gr::io_signature::make3(
3, 3, sizeof(gr_complex), sizeof(gr_complex), sizeof(float)),
gr::io_signature::make(1, 1, sizeof(gr_complex))), gr::io_signature::make(1, 1, sizeof(gr_complex))),
d_log(log), d_log(log),
d_debug(debug), d_debug(debug),
@@ -39,14 +41,17 @@ sync_short_impl(double threshold, unsigned int min_plateau, bool log, bool debug
d_freq_offset(0), d_freq_offset(0),
d_copied(0), d_copied(0),
MIN_PLATEAU(min_plateau), MIN_PLATEAU(min_plateau),
d_threshold(threshold) { d_threshold(threshold)
{
set_tag_propagation_policy(block::TPP_DONT); set_tag_propagation_policy(block::TPP_DONT);
} }
int general_work (int noutput_items, gr_vector_int& ninput_items, int general_work(int noutput_items,
gr_vector_int& ninput_items,
gr_vector_const_void_star& input_items, gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items) { gr_vector_void_star& output_items)
{
const gr_complex* in = (const gr_complex*)input_items[0]; const gr_complex* in = (const gr_complex*)input_items[0];
const gr_complex* in_abs = (const gr_complex*)input_items[1]; const gr_complex* in_abs = (const gr_complex*)input_items[1];
@@ -54,9 +59,11 @@ int general_work (int noutput_items, gr_vector_int& ninput_items,
gr_complex* out = (gr_complex*)output_items[0]; gr_complex* out = (gr_complex*)output_items[0];
int noutput = noutput_items; int noutput = noutput_items;
int ninput = std::min(std::min(ninput_items[0], ninput_items[1]), ninput_items[2]); int ninput =
std::min(std::min(ninput_items[0], ninput_items[1]), ninput_items[2]);
// dout << "SHORT noutput : " << noutput << " ninput: " << ninput_items[0] << std::endl; // dout << "SHORT noutput : " << noutput << " ninput: " << ninput_items[0] <<
// std::endl;
switch (d_state) { switch (d_state) {
@@ -99,7 +106,8 @@ int general_work (int noutput_items, gr_vector_int& ninput_items,
d_copied = 0; d_copied = 0;
d_plateau = 0; d_plateau = 0;
d_freq_offset = arg(in_abs[o]) / 16; d_freq_offset = arg(in_abs[o]) / 16;
insert_tag(nitems_written(0) + o, d_freq_offset, nitems_read(0) + o); insert_tag(
nitems_written(0) + o, d_freq_offset, nitems_read(0) + o);
dout << "SHORT Frame!" << std::endl; dout << "SHORT Frame!" << std::endl;
break; break;
} }
@@ -128,7 +136,8 @@ int general_work (int noutput_items, gr_vector_int& ninput_items,
return 0; return 0;
} }
void insert_tag(uint64_t item, double freq_offset, uint64_t input_item) { void insert_tag(uint64_t item, double freq_offset, uint64_t input_item)
{
mylog(boost::format("frame start at in: %2% out: %1%") % item % input_item); mylog(boost::format("frame start at in: %2% out: %1%") % item % input_item);
const pmt::pmt_t key = pmt::string_to_symbol("wifi_start"); const pmt::pmt_t key = pmt::string_to_symbol("wifi_start");
@@ -149,6 +158,8 @@ private:
}; };
sync_short::sptr sync_short::sptr
sync_short::make(double threshold, unsigned int min_plateau, bool log, bool debug) { sync_short::make(double threshold, unsigned int min_plateau, bool log, bool debug)
return gnuradio::get_initial_sptr(new sync_short_impl(threshold, min_plateau, log, debug)); {
return gnuradio::get_initial_sptr(
new sync_short_impl(threshold, min_plateau, log, debug));
} }
+26 -15
View File
@@ -16,11 +16,12 @@
*/ */
#include "utils.h" #include "utils.h"
#include <math.h>
#include <cassert> #include <cassert>
#include <cstring> #include <cstring>
#include <math.h>
ofdm_param::ofdm_param(Encoding e) { ofdm_param::ofdm_param(Encoding e)
{
encoding = e; encoding = e;
switch (e) { switch (e) {
@@ -86,8 +87,8 @@ ofdm_param::ofdm_param(Encoding e) {
} }
void void ofdm_param::print()
ofdm_param::print() { {
std::cout << "OFDM Parameters:" << std::endl; std::cout << "OFDM Parameters:" << std::endl;
std::cout << "endcoding :" << encoding << std::endl; std::cout << "endcoding :" << encoding << std::endl;
std::cout << "rate_field :" << (int)rate_field << std::endl; std::cout << "rate_field :" << (int)rate_field << std::endl;
@@ -97,7 +98,8 @@ ofdm_param::print() {
} }
frame_param::frame_param(ofdm_param &ofdm, int psdu_length) { frame_param::frame_param(ofdm_param& ofdm, int psdu_length)
{
psdu_size = psdu_length; psdu_size = psdu_length;
@@ -111,8 +113,8 @@ frame_param::frame_param(ofdm_param &ofdm, int psdu_length) {
n_encoded_bits = n_sym * ofdm.n_cbps; n_encoded_bits = n_sym * ofdm.n_cbps;
} }
void void frame_param::print()
frame_param::print() { {
std::cout << "FRAME Parameters:" << std::endl; std::cout << "FRAME Parameters:" << std::endl;
std::cout << "psdu_size: " << psdu_size << std::endl; std::cout << "psdu_size: " << psdu_size << std::endl;
std::cout << "n_sym: " << n_sym << std::endl; std::cout << "n_sym: " << n_sym << std::endl;
@@ -122,7 +124,8 @@ frame_param::print() {
} }
void scramble(const char *in, char *out, frame_param &frame, char initial_state) { void scramble(const char* in, char* out, frame_param& frame, char initial_state)
{
int state = initial_state; int state = initial_state;
int feedback; int feedback;
@@ -136,12 +139,14 @@ void scramble(const char *in, char *out, frame_param &frame, char initial_state)
} }
void reset_tail_bits(char *scrambled_data, frame_param &frame) { void reset_tail_bits(char* scrambled_data, frame_param& frame)
{
memset(scrambled_data + frame.n_data_bits - frame.n_pad - 6, 0, 6 * sizeof(char)); memset(scrambled_data + frame.n_data_bits - frame.n_pad - 6, 0, 6 * sizeof(char));
} }
int ones(int n) { int ones(int n)
{
int sum = 0; int sum = 0;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
if (n & (1 << i)) { if (n & (1 << i)) {
@@ -152,7 +157,8 @@ int ones(int n) {
} }
void convolutional_encoding(const char *in, char *out, frame_param &frame) { void convolutional_encoding(const char* in, char* out, frame_param& frame)
{
int state = 0; int state = 0;
@@ -165,7 +171,8 @@ void convolutional_encoding(const char *in, char *out, frame_param &frame) {
} }
void puncturing(const char *in, char *out, frame_param &frame, ofdm_param &ofdm) { void puncturing(const char* in, char* out, frame_param& frame, ofdm_param& ofdm)
{
int mod; int mod;
@@ -203,7 +210,9 @@ void puncturing(const char *in, char *out, frame_param &frame, ofdm_param &ofdm)
} }
void interleave(const char *in, char *out, frame_param &frame, ofdm_param &ofdm, bool reverse) { void interleave(
const char* in, char* out, frame_param& frame, ofdm_param& ofdm, bool reverse)
{
int n_cbps = ofdm.n_cbps; int n_cbps = ofdm.n_cbps;
int first[n_cbps]; int first[n_cbps];
@@ -230,7 +239,8 @@ void interleave(const char *in, char *out, frame_param &frame, ofdm_param &ofdm,
} }
void split_symbols(const char *in, char *out, frame_param &frame, ofdm_param &ofdm) { void split_symbols(const char* in, char* out, frame_param& frame, ofdm_param& ofdm)
{
int symbols = frame.n_sym * 48; int symbols = frame.n_sym * 48;
@@ -245,7 +255,8 @@ void split_symbols(const char *in, char *out, frame_param &frame, ofdm_param &of
} }
void generate_bits(const char *psdu, char *data_bits, frame_param &frame) { void generate_bits(const char* psdu, char* data_bits, frame_param& frame)
{
// first 16 bits are zero (SERVICE/DATA field) // first 16 bits are zero (SERVICE/DATA field)
memset(data_bits, 0, 16); memset(data_bits, 0, 16);
+18 -6
View File
@@ -17,9 +17,9 @@
#ifndef INCLUDED_IEEE802_11_UTILS_H #ifndef INCLUDED_IEEE802_11_UTILS_H
#define INCLUDED_IEEE802_11_UTILS_H #define INCLUDED_IEEE802_11_UTILS_H
#include <gnuradio/config.h>
#include <ieee802_11/api.h> #include <ieee802_11/api.h>
#include <ieee802_11/mapper.h> #include <ieee802_11/mapper.h>
#include <gnuradio/config.h>
#include <cinttypes> #include <cinttypes>
#include <iostream> #include <iostream>
@@ -29,7 +29,12 @@
#define MAX_ENCODED_BITS ((16 + 8 * MAX_PSDU_SIZE + 6) * 2 + 288) #define MAX_ENCODED_BITS ((16 + 8 * MAX_PSDU_SIZE + 6) * 2 + 288)
#define dout d_debug&& std::cout #define dout d_debug&& std::cout
#define mylog(msg) do { if(d_log) { GR_LOG_INFO(d_logger, msg); }} while(0); #define mylog(msg) \
do { \
if (d_log) { \
GR_LOG_INFO(d_logger, msg); \
} \
} while (0);
struct mac_header { struct mac_header {
// protocol version, type, subtype, to_ds, from_ds, ... // protocol version, type, subtype, to_ds, from_ds, ...
@@ -44,7 +49,8 @@ struct mac_header {
/** /**
* WIFI parameters * WIFI parameters
*/ */
class ofdm_param { class ofdm_param
{
public: public:
ofdm_param(Encoding e); ofdm_param(Encoding e);
@@ -65,7 +71,8 @@ public:
/** /**
* packet specific parameters * packet specific parameters
*/ */
class frame_param { class frame_param
{
public: public:
frame_param(ofdm_param& ofdm, int psdu_length); frame_param(ofdm_param& ofdm, int psdu_length);
// PSDU size in bytes // PSDU size in bytes
@@ -93,7 +100,8 @@ public:
* will be stored * will be stored
* \param seq sequence number of the frame * \param seq sequence number of the frame
*/ */
void generate_mac_data_frame(const char *msdu, int msdu_size, char **psdu, int *psdu_size, char seq); void generate_mac_data_frame(
const char* msdu, int msdu_size, char** psdu, int* psdu_size, char seq);
void scramble(const char* input, char* out, frame_param& frame, char initial_state); void scramble(const char* input, char* out, frame_param& frame, char initial_state);
@@ -103,7 +111,11 @@ void convolutional_encoding(const char *input, char *out, frame_param &frame);
void puncturing(const char* input, char* out, frame_param& frame, ofdm_param& ofdm); void puncturing(const char* input, char* out, frame_param& frame, ofdm_param& ofdm);
void interleave(const char *input, char *out, frame_param &frame, ofdm_param &ofdm, bool reverse = false); void interleave(const char* input,
char* out,
frame_param& frame,
ofdm_param& ofdm,
bool reverse = false);
void split_symbols(const char* input, char* out, frame_param& frame, ofdm_param& ofdm); void split_symbols(const char* input, char* out, frame_param& frame, ofdm_param& ofdm);
+13 -39
View File
@@ -21,15 +21,12 @@
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
base::base() : base::base() : d_store_pos(0) {}
d_store_pos(0) {
}
base::~base() { base::~base() {}
}
uint8_t* uint8_t* base::depuncture(uint8_t* in)
base::depuncture(uint8_t *in) { {
int count; int count;
int n_cbps = d_ofdm->n_cbps; int n_cbps = d_ofdm->n_cbps;
@@ -66,38 +63,15 @@ base::depuncture(uint8_t *in) {
/* Parity lookup table */ /* Parity lookup table */
const unsigned char base::PARTAB[256] = { const unsigned char base::PARTAB[256] = {
0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0,
1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0,
}; };
const unsigned char base::PUNCTURE_1_2[2] = { 1, 1 }; const unsigned char base::PUNCTURE_1_2[2] = { 1, 1 };
-1
View File
@@ -33,7 +33,6 @@ namespace ieee802_11 {
class base class base
{ {
public: public:
base(); base();
~base(); ~base();
virtual uint8_t* decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in) = 0; virtual uint8_t* decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in) = 0;
+40 -30
View File
@@ -56,7 +56,8 @@
* would spill over into memory. * would spill over into memory.
*/ */
#define BUTTERFLY(i,sym) { \ #define BUTTERFLY(i, sym) \
{ \
int m0, m1, m2, m3; \ int m0, m1, m2, m3; \
/* ACS for 0 branch */ \ /* ACS for 0 branch */ \
m0 = state[i].metric + mets[sym]; /* 2*i */ \ m0 = state[i].metric + mets[sym]; /* 2*i */ \
@@ -83,9 +84,10 @@
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
void void viterbi_decoder::viterbi_butterfly2_generic(unsigned char* symbols,
viterbi_decoder::viterbi_butterfly2_generic(unsigned char *symbols, unsigned char* mm0,
unsigned char *mm0, unsigned char *mm1, unsigned char *pp0, unsigned char* mm1,
unsigned char* pp0,
unsigned char* pp1) unsigned char* pp1)
{ {
int i, j, k; int i, j, k;
@@ -100,7 +102,8 @@ viterbi_decoder::viterbi_butterfly2_generic(unsigned char *symbols,
// Operate on 4 symbols (2 bits) at a time // Operate on 4 symbols (2 bits) at a time
unsigned char m0[16], m1[16], m2[16], m3[16], decision0[16], decision1[16], survivor0[16], survivor1[16]; unsigned char m0[16], m1[16], m2[16], m3[16], decision0[16], decision1[16],
survivor0[16], survivor1[16];
unsigned char metsv[16], metsvm[16]; unsigned char metsv[16], metsvm[16];
unsigned char shift0[16], shift1[16]; unsigned char shift0[16], shift1[16];
unsigned char tmp0[16], tmp1[16]; unsigned char tmp0[16], tmp1[16];
@@ -118,16 +121,15 @@ viterbi_decoder::viterbi_butterfly2_generic(unsigned char *symbols,
metsvm[j] = d_branchtab27_generic[1].c[(i * 16) + j] ^ sym1v[j]; metsvm[j] = d_branchtab27_generic[1].c[(i * 16) + j] ^ sym1v[j];
metsv[j] = 1 - metsvm[j]; metsv[j] = 1 - metsvm[j];
} }
} } else if (symbols[1] == 2) {
else if (symbols[1] == 2) {
for (j = 0; j < 16; j++) { for (j = 0; j < 16; j++) {
metsvm[j] = d_branchtab27_generic[0].c[(i * 16) + j] ^ sym0v[j]; metsvm[j] = d_branchtab27_generic[0].c[(i * 16) + j] ^ sym0v[j];
metsv[j] = 1 - metsvm[j]; metsv[j] = 1 - metsvm[j];
} }
} } else {
else {
for (j = 0; j < 16; j++) { for (j = 0; j < 16; j++) {
metsvm[j] = (d_branchtab27_generic[0].c[(i*16) + j] ^ sym0v[j]) + (d_branchtab27_generic[1].c[(i*16) + j] ^ sym1v[j]); metsvm[j] = (d_branchtab27_generic[0].c[(i * 16) + j] ^ sym0v[j]) +
(d_branchtab27_generic[1].c[(i * 16) + j] ^ sym1v[j]);
metsv[j] = 2 - metsvm[j]; metsv[j] = 2 - metsvm[j];
} }
} }
@@ -205,16 +207,15 @@ viterbi_decoder::viterbi_butterfly2_generic(unsigned char *symbols,
metsvm[j] = d_branchtab27_generic[1].c[(i * 16) + j] ^ sym1v[j]; metsvm[j] = d_branchtab27_generic[1].c[(i * 16) + j] ^ sym1v[j];
metsv[j] = 1 - metsvm[j]; metsv[j] = 1 - metsvm[j];
} }
} } else if (symbols[3] == 2) {
else if (symbols[3] == 2) {
for (j = 0; j < 16; j++) { for (j = 0; j < 16; j++) {
metsvm[j] = d_branchtab27_generic[0].c[(i * 16) + j] ^ sym0v[j]; metsvm[j] = d_branchtab27_generic[0].c[(i * 16) + j] ^ sym0v[j];
metsv[j] = 1 - metsvm[j]; metsv[j] = 1 - metsvm[j];
} }
} } else {
else {
for (j = 0; j < 16; j++) { for (j = 0; j < 16; j++) {
metsvm[j] = (d_branchtab27_generic[0].c[(i*16) + j] ^ sym0v[j]) + (d_branchtab27_generic[1].c[(i*16) + j] ^ sym1v[j]); metsvm[j] = (d_branchtab27_generic[0].c[(i * 16) + j] ^ sym0v[j]) +
(d_branchtab27_generic[1].c[(i * 16) + j] ^ sym1v[j]);
metsv[j] = 2 - metsvm[j]; metsv[j] = 2 - metsvm[j];
} }
} }
@@ -278,9 +279,11 @@ viterbi_decoder::viterbi_butterfly2_generic(unsigned char *symbols,
} }
// Find current best path // Find current best path
unsigned char unsigned char viterbi_decoder::viterbi_get_output_generic(unsigned char* mm0,
viterbi_decoder::viterbi_get_output_generic(unsigned char *mm0, unsigned char* pp0,
unsigned char *pp0, int ntraceback, unsigned char *outbuf) { int ntraceback,
unsigned char* outbuf)
{
int i; int i;
int bestmetric, minmetric; int bestmetric, minmetric;
int beststate = 0; int beststate = 0;
@@ -333,8 +336,8 @@ viterbi_decoder::viterbi_get_output_generic(unsigned char *mm0,
return bestmetric; return bestmetric;
} }
uint8_t* uint8_t* viterbi_decoder::decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in)
viterbi_decoder::decode(ofdm_param *ofdm, frame_param *frame, uint8_t *in) { {
d_ofdm = ofdm; d_ofdm = ofdm;
d_frame = frame; d_frame = frame;
@@ -349,17 +352,22 @@ viterbi_decoder::decode(ofdm_param *ofdm, frame_param *frame, uint8_t *in) {
while (n_decoded < d_frame->n_data_bits) { while (n_decoded < d_frame->n_data_bits) {
if ((in_count % 4) == 0) { // 0 or 3 if ((in_count % 4) == 0) { // 0 or 3
viterbi_butterfly2_generic(&depunctured[in_count & 0xfffffffc], d_metric0_generic, d_metric1_generic, viterbi_butterfly2_generic(&depunctured[in_count & 0xfffffffc],
d_path0_generic, d_path1_generic); d_metric0_generic,
d_metric1_generic,
d_path0_generic,
d_path1_generic);
if ((in_count > 0) && (in_count % 16) == 8) { // 8 or 11 if ((in_count > 0) && (in_count % 16) == 8) { // 8 or 11
unsigned char c; unsigned char c;
viterbi_get_output_generic(d_metric0_generic, d_path0_generic, d_ntraceback, &c); viterbi_get_output_generic(
d_metric0_generic, d_path0_generic, d_ntraceback, &c);
if (out_count >= d_ntraceback) { if (out_count >= d_ntraceback) {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
d_decoded[(out_count - d_ntraceback) * 8 + i] = (c >> (7 - i)) & 0x1; d_decoded[(out_count - d_ntraceback) * 8 + i] =
(c >> (7 - i)) & 0x1;
n_decoded++; n_decoded++;
} }
} }
@@ -372,8 +380,8 @@ viterbi_decoder::decode(ofdm_param *ofdm, frame_param *frame, uint8_t *in) {
return d_decoded; return d_decoded;
} }
void void viterbi_decoder::reset()
viterbi_decoder::reset() { {
viterbi_chunks_init_generic(); viterbi_chunks_init_generic();
@@ -402,8 +410,8 @@ viterbi_decoder::reset() {
} }
// Initialize starting metrics to prefer 0 state // Initialize starting metrics to prefer 0 state
void void viterbi_decoder::viterbi_chunks_init_generic()
viterbi_decoder::viterbi_chunks_init_generic() { {
int i, j; int i, j;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@@ -413,8 +421,10 @@ viterbi_decoder::viterbi_chunks_init_generic() {
int polys[2] = { 0x6d, 0x4f }; int polys[2] = { 0x6d, 0x4f };
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
d_branchtab27_generic[0].c[i] = (polys[0] < 0) ^ PARTAB[(2*i) & abs(polys[0])] ? 1 : 0; d_branchtab27_generic[0].c[i] =
d_branchtab27_generic[1].c[i] = (polys[1] < 0) ^ PARTAB[(2*i) & abs(polys[1])] ? 1 : 0; (polys[0] < 0) ^ PARTAB[(2 * i) & abs(polys[0])] ? 1 : 0;
d_branchtab27_generic[1].c[i] =
(polys[1] < 0) ^ PARTAB[(2 * i) & abs(polys[1])] ? 1 : 0;
} }
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
@@ -30,11 +30,9 @@ namespace ieee802_11 {
class viterbi_decoder : public base class viterbi_decoder : public base
{ {
public: public:
virtual uint8_t* decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in); virtual uint8_t* decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in);
private: private:
union branchtab27 { union branchtab27 {
unsigned char c[32]; unsigned char c[32];
} d_branchtab27_generic[2]; } d_branchtab27_generic[2];
@@ -48,10 +46,14 @@ private:
void viterbi_chunks_init_generic(); void viterbi_chunks_init_generic();
void viterbi_butterfly2_generic(unsigned char* symbols, void viterbi_butterfly2_generic(unsigned char* symbols,
unsigned char m0[], unsigned char m1[], unsigned char p0[], unsigned char m0[],
unsigned char m1[],
unsigned char p0[],
unsigned char p1[]); unsigned char p1[]);
unsigned char viterbi_get_output_generic(unsigned char* mm0, unsigned char viterbi_get_output_generic(unsigned char* mm0,
unsigned char *pp0, int ntraceback, unsigned char *outbuf); unsigned char* pp0,
int ntraceback,
unsigned char* outbuf);
}; };
} // namespace ieee802_11 } // namespace ieee802_11
+47 -27
View File
@@ -56,7 +56,8 @@
* would spill over into memory. * would spill over into memory.
*/ */
#define BUTTERFLY(i,sym) { \ #define BUTTERFLY(i, sym) \
{ \
int m0, m1, m2, m3; \ int m0, m1, m2, m3; \
/* ACS for 0 branch */ \ /* ACS for 0 branch */ \
m0 = state[i].metric + mets[sym]; /* 2*i */ \ m0 = state[i].metric + mets[sym]; /* 2*i */ \
@@ -82,9 +83,9 @@
using namespace gr::ieee802_11; using namespace gr::ieee802_11;
void void viterbi_decoder::viterbi_butterfly2_sse2(
viterbi_decoder::viterbi_butterfly2_sse2(unsigned char *symbols, unsigned char* symbols, __m128i* mm0, __m128i* mm1, __m128i* pp0, __m128i* pp1)
__m128i *mm0, __m128i *mm1, __m128i *pp0, __m128i *pp1) { {
int i; int i;
__m128i *metric0, *metric1; __m128i *metric0, *metric1;
@@ -114,7 +115,8 @@ viterbi_decoder::viterbi_butterfly2_sse2(unsigned char *symbols,
metsvm = _mm_xor_si128(d_branchtab27_sse2[0].v[i], sym0v); metsvm = _mm_xor_si128(d_branchtab27_sse2[0].v[i], sym0v);
metsv = _mm_sub_epi8(_mm_set1_epi8(1), metsvm); metsv = _mm_sub_epi8(_mm_set1_epi8(1), metsvm);
} else { } else {
metsvm = _mm_add_epi8(_mm_xor_si128(d_branchtab27_sse2[0].v[i],sym0v),_mm_xor_si128(d_branchtab27_sse2[1].v[i],sym1v)); metsvm = _mm_add_epi8(_mm_xor_si128(d_branchtab27_sse2[0].v[i], sym0v),
_mm_xor_si128(d_branchtab27_sse2[1].v[i], sym1v));
metsv = _mm_sub_epi8(_mm_set1_epi8(2), metsvm); metsv = _mm_sub_epi8(_mm_set1_epi8(2), metsvm);
} }
@@ -125,18 +127,22 @@ viterbi_decoder::viterbi_butterfly2_sse2(unsigned char *symbols,
decision0 = _mm_cmpgt_epi8(_mm_sub_epi8(m0, m1), _mm_setzero_si128()); decision0 = _mm_cmpgt_epi8(_mm_sub_epi8(m0, m1), _mm_setzero_si128());
decision1 = _mm_cmpgt_epi8(_mm_sub_epi8(m2, m3), _mm_setzero_si128()); decision1 = _mm_cmpgt_epi8(_mm_sub_epi8(m2, m3), _mm_setzero_si128());
survivor0 = _mm_or_si128(_mm_and_si128(decision0,m0),_mm_andnot_si128(decision0,m1)); survivor0 =
survivor1 = _mm_or_si128(_mm_and_si128(decision1,m2),_mm_andnot_si128(decision1,m3)); _mm_or_si128(_mm_and_si128(decision0, m0), _mm_andnot_si128(decision0, m1));
survivor1 =
_mm_or_si128(_mm_and_si128(decision1, m2), _mm_andnot_si128(decision1, m3));
shift0 = _mm_slli_epi16(path0[i], 1); shift0 = _mm_slli_epi16(path0[i], 1);
shift1 = _mm_slli_epi16(path0[2 + i], 1); shift1 = _mm_slli_epi16(path0[2 + i], 1);
shift1 = _mm_add_epi8(shift1, _mm_set1_epi8(1)); shift1 = _mm_add_epi8(shift1, _mm_set1_epi8(1));
metric1[2 * i] = _mm_unpacklo_epi8(survivor0, survivor1); metric1[2 * i] = _mm_unpacklo_epi8(survivor0, survivor1);
tmp0 = _mm_or_si128(_mm_and_si128(decision0,shift0),_mm_andnot_si128(decision0,shift1)); tmp0 = _mm_or_si128(_mm_and_si128(decision0, shift0),
_mm_andnot_si128(decision0, shift1));
metric1[2 * i + 1] = _mm_unpackhi_epi8(survivor0, survivor1); metric1[2 * i + 1] = _mm_unpackhi_epi8(survivor0, survivor1);
tmp1 = _mm_or_si128(_mm_and_si128(decision1,shift0),_mm_andnot_si128(decision1,shift1)); tmp1 = _mm_or_si128(_mm_and_si128(decision1, shift0),
_mm_andnot_si128(decision1, shift1));
path1[2 * i] = _mm_unpacklo_epi8(tmp0, tmp1); path1[2 * i] = _mm_unpacklo_epi8(tmp0, tmp1);
path1[2 * i + 1] = _mm_unpackhi_epi8(tmp0, tmp1); path1[2 * i + 1] = _mm_unpackhi_epi8(tmp0, tmp1);
@@ -160,7 +166,8 @@ viterbi_decoder::viterbi_butterfly2_sse2(unsigned char *symbols,
metsv = _mm_sub_epi8(_mm_set1_epi8(1), metsvm); metsv = _mm_sub_epi8(_mm_set1_epi8(1), metsvm);
} else { } else {
metsvm = _mm_add_epi8(_mm_xor_si128(d_branchtab27_sse2[0].v[i],sym0v),_mm_xor_si128(d_branchtab27_sse2[1].v[i],sym1v)); metsvm = _mm_add_epi8(_mm_xor_si128(d_branchtab27_sse2[0].v[i], sym0v),
_mm_xor_si128(d_branchtab27_sse2[1].v[i], sym1v));
metsv = _mm_sub_epi8(_mm_set1_epi8(2), metsvm); metsv = _mm_sub_epi8(_mm_set1_epi8(2), metsvm);
} }
@@ -171,18 +178,22 @@ viterbi_decoder::viterbi_butterfly2_sse2(unsigned char *symbols,
decision0 = _mm_cmpgt_epi8(_mm_sub_epi8(m0, m1), _mm_setzero_si128()); decision0 = _mm_cmpgt_epi8(_mm_sub_epi8(m0, m1), _mm_setzero_si128());
decision1 = _mm_cmpgt_epi8(_mm_sub_epi8(m2, m3), _mm_setzero_si128()); decision1 = _mm_cmpgt_epi8(_mm_sub_epi8(m2, m3), _mm_setzero_si128());
survivor0 = _mm_or_si128(_mm_and_si128(decision0,m0),_mm_andnot_si128(decision0,m1)); survivor0 =
survivor1 = _mm_or_si128(_mm_and_si128(decision1,m2),_mm_andnot_si128(decision1,m3)); _mm_or_si128(_mm_and_si128(decision0, m0), _mm_andnot_si128(decision0, m1));
survivor1 =
_mm_or_si128(_mm_and_si128(decision1, m2), _mm_andnot_si128(decision1, m3));
shift0 = _mm_slli_epi16(path0[i], 1); shift0 = _mm_slli_epi16(path0[i], 1);
shift1 = _mm_slli_epi16(path0[2 + i], 1); shift1 = _mm_slli_epi16(path0[2 + i], 1);
shift1 = _mm_add_epi8(shift1, _mm_set1_epi8(1)); shift1 = _mm_add_epi8(shift1, _mm_set1_epi8(1));
metric1[2 * i] = _mm_unpacklo_epi8(survivor0, survivor1); metric1[2 * i] = _mm_unpacklo_epi8(survivor0, survivor1);
tmp0 = _mm_or_si128(_mm_and_si128(decision0,shift0),_mm_andnot_si128(decision0,shift1)); tmp0 = _mm_or_si128(_mm_and_si128(decision0, shift0),
_mm_andnot_si128(decision0, shift1));
metric1[2 * i + 1] = _mm_unpackhi_epi8(survivor0, survivor1); metric1[2 * i + 1] = _mm_unpackhi_epi8(survivor0, survivor1);
tmp1 = _mm_or_si128(_mm_and_si128(decision1,shift0),_mm_andnot_si128(decision1,shift1)); tmp1 = _mm_or_si128(_mm_and_si128(decision1, shift0),
_mm_andnot_si128(decision1, shift1));
path1[2 * i] = _mm_unpacklo_epi8(tmp0, tmp1); path1[2 * i] = _mm_unpacklo_epi8(tmp0, tmp1);
path1[2 * i + 1] = _mm_unpackhi_epi8(tmp0, tmp1); path1[2 * i + 1] = _mm_unpackhi_epi8(tmp0, tmp1);
@@ -190,9 +201,11 @@ viterbi_decoder::viterbi_butterfly2_sse2(unsigned char *symbols,
} }
// Find current best path // Find current best path
unsigned char unsigned char viterbi_decoder::viterbi_get_output_sse2(__m128i* mm0,
viterbi_decoder::viterbi_get_output_sse2(__m128i *mm0, __m128i *pp0, __m128i* pp0,
int ntraceback, unsigned char *outbuf) { int ntraceback,
unsigned char* outbuf)
{
int i; int i;
int bestmetric, minmetric; int bestmetric, minmetric;
int beststate = 0; int beststate = 0;
@@ -243,8 +256,8 @@ viterbi_decoder::viterbi_get_output_sse2(__m128i *mm0, __m128i *pp0,
} }
uint8_t* uint8_t* viterbi_decoder::decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in)
viterbi_decoder::decode(ofdm_param *ofdm, frame_param *frame, uint8_t *in) { {
d_ofdm = ofdm; d_ofdm = ofdm;
d_frame = frame; d_frame = frame;
@@ -259,7 +272,11 @@ viterbi_decoder::decode(ofdm_param *ofdm, frame_param *frame, uint8_t *in) {
while (n_decoded < d_frame->n_data_bits) { while (n_decoded < d_frame->n_data_bits) {
if ((in_count % 4) == 0) { // 0 or 3 if ((in_count % 4) == 0) { // 0 or 3
viterbi_butterfly2_sse2(&depunctured[in_count & 0xfffffffc], d_metric0, d_metric1, d_path0, d_path1); viterbi_butterfly2_sse2(&depunctured[in_count & 0xfffffffc],
d_metric0,
d_metric1,
d_path0,
d_path1);
if ((in_count > 0) && (in_count % 16) == 8) { // 8 or 11 if ((in_count > 0) && (in_count % 16) == 8) { // 8 or 11
unsigned char c; unsigned char c;
@@ -268,7 +285,8 @@ viterbi_decoder::decode(ofdm_param *ofdm, frame_param *frame, uint8_t *in) {
if (out_count >= d_ntraceback) { if (out_count >= d_ntraceback) {
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
d_decoded[(out_count - d_ntraceback) * 8 + i] = (c >> (7 - i)) & 0x1; d_decoded[(out_count - d_ntraceback) * 8 + i] =
(c >> (7 - i)) & 0x1;
n_decoded++; n_decoded++;
} }
} }
@@ -281,8 +299,8 @@ viterbi_decoder::decode(ofdm_param *ofdm, frame_param *frame, uint8_t *in) {
return d_decoded; return d_decoded;
} }
void void viterbi_decoder::reset()
viterbi_decoder::reset() { {
viterbi_chunks_init_sse2(); viterbi_chunks_init_sse2();
@@ -311,8 +329,8 @@ viterbi_decoder::reset() {
} }
// Initialize starting metrics to prefer 0 state // Initialize starting metrics to prefer 0 state
void void viterbi_decoder::viterbi_chunks_init_sse2()
viterbi_decoder::viterbi_chunks_init_sse2() { {
int i, j; int i, j;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
@@ -322,8 +340,10 @@ viterbi_decoder::viterbi_chunks_init_sse2() {
int polys[2] = { 0x6d, 0x4f }; int polys[2] = { 0x6d, 0x4f };
for (i = 0; i < 32; i++) { for (i = 0; i < 32; i++) {
d_branchtab27_sse2[0].c[i] = (polys[0] < 0) ^ PARTAB[(2*i) & abs(polys[0])] ? 1 : 0; d_branchtab27_sse2[0].c[i] =
d_branchtab27_sse2[1].c[i] = (polys[1] < 0) ^ PARTAB[(2*i) & abs(polys[1])] ? 1 : 0; (polys[0] < 0) ^ PARTAB[(2 * i) & abs(polys[0])] ? 1 : 0;
d_branchtab27_sse2[1].c[i] =
(polys[1] < 0) ^ PARTAB[(2 * i) & abs(polys[1])] ? 1 : 0;
} }
for (i = 0; i < 64; i++) { for (i = 0; i < 64; i++) {
+6 -6
View File
@@ -17,8 +17,8 @@
#ifndef INCLUDED_IEEE802_11_VITERBI_DECODER_X86_H #ifndef INCLUDED_IEEE802_11_VITERBI_DECODER_X86_H
#define INCLUDED_IEEE802_11_VITERBI_DECODER_X86_H #define INCLUDED_IEEE802_11_VITERBI_DECODER_X86_H
#include <xmmintrin.h>
#include "base.h" #include "base.h"
#include <xmmintrin.h>
namespace gr { namespace gr {
namespace ieee802_11 { namespace ieee802_11 {
@@ -31,11 +31,9 @@ namespace ieee802_11 {
class viterbi_decoder : public base class viterbi_decoder : public base
{ {
public: public:
virtual uint8_t* decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in); virtual uint8_t* decode(ofdm_param* ofdm, frame_param* frame, uint8_t* in);
private: private:
union branchtab27 { union branchtab27 {
unsigned char c[32]; unsigned char c[32];
__m128i v[2]; __m128i v[2];
@@ -49,10 +47,12 @@ private:
virtual void reset(); virtual void reset();
void viterbi_chunks_init_sse2(); void viterbi_chunks_init_sse2();
void viterbi_butterfly2_sse2(unsigned char *symbols, void viterbi_butterfly2_sse2(
__m128i m0[], __m128i m1[], __m128i p0[], __m128i p1[]); unsigned char* symbols, __m128i m0[], __m128i m1[], __m128i p0[], __m128i p1[]);
unsigned char viterbi_get_output_sse2(__m128i* mm0, unsigned char viterbi_get_output_sse2(__m128i* mm0,
__m128i *pp0, int ntraceback, unsigned char *outbuf); __m128i* pp0,
int ntraceback,
unsigned char* outbuf);
}; };
} // namespace ieee802_11 } // namespace ieee802_11