Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fac8b1ce9 | |||
| 948f1c80ae | |||
| f85bfca13a | |||
| 8814b4b333 | |||
| 7565ec5246 | |||
| 2c95b5e07f | |||
| df4f14f220 | |||
| c664ac99a7 | |||
| 9614b4a459 | |||
| 73095d93f3 | |||
| cf0af12054 | |||
| c8de2646ae | |||
| 1d682b172b | |||
| f2dc4c4f0b | |||
| 137cc3e944 | |||
| 8300907d85 | |||
| 73317734f3 | |||
| 023ede6821 | |||
| e1dbdef395 | |||
| a04945a35b | |||
| fe4ae7f802 |
Executable
+56
@@ -0,0 +1,56 @@
|
||||
#!/bin/bash
|
||||
|
||||
FILE="/tmp/ofdm.pcap"
|
||||
FLOWGRAPH="rx_agc_demo.py"
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
### create fifo
|
||||
if [ -e ${FILE} ]
|
||||
then
|
||||
echo "${FILE}: file already exists"
|
||||
if ! [ -p ${FILE} ]
|
||||
then
|
||||
echo "ERROR: ${FILE} exists and is not a FIFO"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "creating fifo: ${FILE}"
|
||||
mkfifo ${FILE}
|
||||
fi
|
||||
|
||||
|
||||
### create tap interface
|
||||
if [[ `ifconfig -a | grep tap0 | wc -l` -eq 0 ]]
|
||||
then
|
||||
sudo ip tuntap add dev tap0 user ${USER} mode tap
|
||||
fi
|
||||
|
||||
### reconfigure it in any case, just to be sure it's up
|
||||
sudo ifconfig tap0 down
|
||||
sudo ifconfig tap0 hw ether 12:34:56:78:90:ab
|
||||
sudo ifconfig tap0 up
|
||||
sudo ifconfig tap0 192.168.123.1
|
||||
|
||||
|
||||
### start transceiver
|
||||
cd ${DIR}
|
||||
cd ../examples/
|
||||
./${FLOWGRAPH} &
|
||||
sleep 1
|
||||
|
||||
|
||||
### start wireshark
|
||||
wireshark -k -i ${FILE} &
|
||||
sleep 1
|
||||
|
||||
|
||||
### start netcat
|
||||
echo "##########################################################################"
|
||||
echo "### starting netcat. Just type and the lines will be send to the flowgraph"
|
||||
echo "##########################################################################"
|
||||
sleep 2
|
||||
|
||||
#echo | nc -u localhost 52001
|
||||
cat
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<block>
|
||||
<name>WiFi EDCA</name>
|
||||
<key>ieee802_11_wifi_edca</key>
|
||||
<category>IEEE802.11</category>
|
||||
<import>import ieee802_11</import>
|
||||
<make>ieee802_11.wifi_edca($cw_min, $aifsn)</make>
|
||||
|
||||
<param>
|
||||
<name>CW min</name>
|
||||
<key>cw_min</key>
|
||||
<value>[15, 15, 7, 3]</value>
|
||||
<type>int_vector</type>
|
||||
</param>
|
||||
|
||||
<param>
|
||||
<name>AIFSN [slots]</name>
|
||||
<key>aifsn</key>
|
||||
<value>[9, 6, 3, 2]</value>
|
||||
<type>int_vector</type>
|
||||
</param>
|
||||
|
||||
<check>len($cw_min) == len($aifsn)</check>
|
||||
|
||||
<sink>
|
||||
<name>ac in</name>
|
||||
<type>message</type>
|
||||
<nports>len($cw_min)</nports>
|
||||
<optional>1</optional>
|
||||
</sink>
|
||||
|
||||
<source>
|
||||
<name>mac out</name>
|
||||
<type>message</type>
|
||||
</source>
|
||||
</block>
|
||||
@@ -79,6 +79,7 @@ list(APPEND include_sources
|
||||
ofdm_parse_mac.h
|
||||
ofdm_sync_long.h
|
||||
ofdm_sync_short.h
|
||||
wifi_edca.h
|
||||
wifi_signal_field.h
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef INCLUDED_IEEE802_11_WIFI_EDCA_H
|
||||
#define INCLUDED_IEEE802_11_WIFI_EDCA_H
|
||||
|
||||
#include <ieee802-11/api.h>
|
||||
#include <gnuradio/block.h>
|
||||
|
||||
namespace gr {
|
||||
namespace ieee802_11 {
|
||||
|
||||
class IEEE802_11_API wifi_edca : virtual public block
|
||||
{
|
||||
public:
|
||||
|
||||
typedef boost::shared_ptr<wifi_edca> sptr;
|
||||
static sptr make(std::vector<uint16_t>cw_min, std::vector<uint16_t>aifsn);
|
||||
};
|
||||
|
||||
} // namespace ieee802_11
|
||||
} // namespace gr
|
||||
|
||||
#endif /* INCLUDED_IEEE802_11_WIFI_EDCA_H */
|
||||
@@ -107,6 +107,7 @@ list(APPEND gr_ieee802_11_sources
|
||||
ofdm_sync_long.cc
|
||||
ofdm_sync_short.cc
|
||||
utils.cc
|
||||
wifi_edca.cc
|
||||
wifi_signal_field_impl.cc
|
||||
)
|
||||
|
||||
|
||||
+17
-2
@@ -84,6 +84,9 @@ void app_in (pmt::pmt_t msg) {
|
||||
size_t msg_len;
|
||||
const char *msdu;
|
||||
|
||||
// dict
|
||||
pmt::pmt_t dict = pmt::make_dict();
|
||||
|
||||
if(pmt::is_eof_object(msg)) {
|
||||
message_port_pub(pmt::mp("phy out"), pmt::PMT_EOF);
|
||||
detail().get()->set_done(true);
|
||||
@@ -98,6 +101,7 @@ void app_in (pmt::pmt_t msg) {
|
||||
|
||||
} else if(pmt::is_pair(msg)) {
|
||||
|
||||
dict = pmt::car(msg);
|
||||
msg_len = pmt::blob_length(pmt::cdr(msg));
|
||||
msdu = reinterpret_cast<const char *>(pmt::blob_data(pmt::cdr(msg)));
|
||||
|
||||
@@ -114,10 +118,21 @@ void app_in (pmt::pmt_t msg) {
|
||||
int psdu_length;
|
||||
generate_mac_data_frame(msdu, msg_len, &psdu_length);
|
||||
|
||||
// dict
|
||||
pmt::pmt_t dict = pmt::make_dict();
|
||||
dict = pmt::dict_add(dict, pmt::mp("crc_included"), pmt::PMT_T);
|
||||
|
||||
// check if csma is enabled
|
||||
pmt::pmt_t pmt_cw = pmt::dict_ref(dict, pmt::mp("cw_min"), pmt::PMT_NIL);
|
||||
if(pmt_cw != pmt::PMT_NIL) {
|
||||
uint64_t cw = pmt::to_long(pmt_cw);
|
||||
pmt::pmt_t backoffs = pmt::make_u64vector(2, 0);
|
||||
pmt::u64vector_set(backoffs, 0, rand() % cw);
|
||||
pmt::u64vector_set(backoffs, 1, rand() % cw);
|
||||
|
||||
dict = pmt::dict_add(dict, pmt::mp("backoffs"), backoffs);
|
||||
dict = pmt::dict_add(dict, pmt::mp("csma"), pmt::PMT_T);
|
||||
}
|
||||
|
||||
|
||||
// blob
|
||||
pmt::pmt_t mac = pmt::make_blob(d_psdu, psdu_length);
|
||||
|
||||
|
||||
@@ -138,6 +138,14 @@ int general_work(int noutput, gr_vector_int& ninput_items,
|
||||
add_item_tag(0, nitems_written(0), pmt::mp("encoding"),
|
||||
encoding, srcid);
|
||||
|
||||
pmt::pmt_t dict_items(pmt::dict_items(pmt::car(msg)));
|
||||
while (!pmt::is_null(dict_items)) {
|
||||
pmt::pmt_t this_item(pmt::car(dict_items));
|
||||
|
||||
add_item_tag(0, nitems_written(0), pmt::car(this_item),
|
||||
pmt::cdr(this_item), srcid);
|
||||
dict_items = pmt::cdr(dict_items);
|
||||
}
|
||||
|
||||
free(data_bits);
|
||||
free(scrambled_data);
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Bastian Bloessl <bloessl@ccs-labs.org>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <ieee802-11/wifi_edca.h>
|
||||
|
||||
#include <gnuradio/io_signature.h>
|
||||
#include <gnuradio/block_detail.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#include <boost/crc.hpp>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace gr::ieee802_11;
|
||||
|
||||
class wifi_edca_impl : public wifi_edca {
|
||||
|
||||
public:
|
||||
|
||||
wifi_edca_impl(std::vector<uint16_t> cw_min, std::vector<uint16_t>aifsn) :
|
||||
block("wifi_edca",
|
||||
gr::io_signature::make(0, 0, 0),
|
||||
gr::io_signature::make(0, 0, 0)),
|
||||
m_cw_min(cw_min), m_aifsn(aifsn)
|
||||
{
|
||||
|
||||
if(cw_min.size() != aifsn.size()) {
|
||||
throw std::invalid_argument("WiFi EDCA: cw_min and aifsn parameters have to have same length");
|
||||
}
|
||||
|
||||
if(cw_min.size() == 0) {
|
||||
throw std::invalid_argument("WiFi EDCA need cw_min and aifsn");
|
||||
}
|
||||
|
||||
message_port_register_out(pmt::mp("mac out"));
|
||||
|
||||
if(cw_min.size() == 1) {
|
||||
message_port_register_in(pmt::mp("ac_in"));
|
||||
set_msg_handler(pmt::mp("ac_in"), boost::bind(&wifi_edca_impl::ac_in, this, _1, 0));
|
||||
} else {
|
||||
for(int i = 0; i < cw_min.size(); i++) {
|
||||
std::stringstream sstm;
|
||||
sstm << "ac in" << i;
|
||||
message_port_register_in(pmt::mp(sstm.str()));
|
||||
set_msg_handler(pmt::mp(sstm.str()), boost::bind(&wifi_edca_impl::ac_in, this, _1, i));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ac_in (pmt::pmt_t msg, int i) {
|
||||
std::cout << "ac " << i << std::endl;
|
||||
|
||||
if(pmt::is_eof_object(msg)) {
|
||||
message_port_pub(pmt::mp("mac out"), pmt::PMT_EOF);
|
||||
detail().get()->set_done(true);
|
||||
|
||||
} else if(pmt::is_symbol(msg)) {
|
||||
|
||||
std::string str;
|
||||
str = pmt::symbol_to_string(msg);
|
||||
|
||||
pmt::pmt_t dict = pmt::make_dict();
|
||||
dict = pmt::dict_add(dict, pmt::mp("cw_min"), pmt::from_long(m_cw_min[i]));
|
||||
dict = pmt::dict_add(dict, pmt::mp("aifsn"), pmt::from_long(m_aifsn[i]));
|
||||
|
||||
pmt::pmt_t blob = pmt::make_blob(str.data(), str.length());
|
||||
pmt::pmt_t pair = pmt::cons(dict, blob);
|
||||
|
||||
message_port_pub(pmt::mp("mac out"), pair);
|
||||
|
||||
} else if(pmt::is_pair(msg)) {
|
||||
pmt::pmt_t dict = pmt::car(msg);
|
||||
dict = pmt::dict_add(dict, pmt::mp("cw_min"), pmt::from_long(m_cw_min[i]));
|
||||
dict = pmt::dict_add(dict, pmt::mp("aifsn"), pmt::from_long(m_aifsn[i]));
|
||||
message_port_pub(pmt::mp("mac out"), pmt::cons(dict, pmt::cdr(msg)));
|
||||
|
||||
} else {
|
||||
throw std::invalid_argument("WiFi EDCA expects PDUs or strings");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<uint16_t>m_cw_min;
|
||||
std::vector<uint16_t>m_aifsn;
|
||||
};
|
||||
|
||||
wifi_edca::sptr
|
||||
wifi_edca::make(std::vector<uint16_t>cw_min, std::vector<uint16_t> aifsn) {
|
||||
return gnuradio::get_initial_sptr(new wifi_edca_impl(cw_min, aifsn));
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "ieee802-11/ofdm_parse_mac.h"
|
||||
#include "ieee802-11/ofdm_sync_long.h"
|
||||
#include "ieee802-11/ofdm_sync_short.h"
|
||||
#include "ieee802-11/wifi_edca.h"
|
||||
#include "ieee802-11/wifi_signal_field.h"
|
||||
%}
|
||||
|
||||
@@ -53,6 +54,7 @@
|
||||
%include "ieee802-11/ofdm_parse_mac.h"
|
||||
%include "ieee802-11/ofdm_sync_long.h"
|
||||
%include "ieee802-11/ofdm_sync_short.h"
|
||||
%include "ieee802-11/wifi_edca.h"
|
||||
%include "ieee802-11/wifi_signal_field.h"
|
||||
|
||||
GR_SWIG_BLOCK_MAGIC2(ieee802_11, chunks_to_symbols);
|
||||
@@ -67,6 +69,7 @@ GR_SWIG_BLOCK_MAGIC2(ieee802_11, ofdm_mapper);
|
||||
GR_SWIG_BLOCK_MAGIC2(ieee802_11, ofdm_parse_mac);
|
||||
GR_SWIG_BLOCK_MAGIC2(ieee802_11, ofdm_sync_long);
|
||||
GR_SWIG_BLOCK_MAGIC2(ieee802_11, ofdm_sync_short);
|
||||
GR_SWIG_BLOCK_MAGIC2(ieee802_11, wifi_edca);
|
||||
|
||||
%template(wifi_signal_field_sptr) boost::shared_ptr<gr::ieee802_11::wifi_signal_field>;
|
||||
%pythoncode %{
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
dB2lin <- function(x) { 10^(x/10) }
|
||||
|
||||
gain.levels <- 0:46 * 2
|
||||
gains <- dB2lin(gain.levels)
|
||||
|
||||
ref.level <- 1/0.03125 # the level we want to tune to
|
||||
ref.gain <- gains[which(gain.levels == 46)] # idle gain setting
|
||||
|
||||
abs.level <- ref.level * ref.gain / gains
|
||||
|
||||
abs.level.int <- round(abs.level * 2**15)
|
||||
|
||||
lna.level <- c(0, 16, 30)
|
||||
lna.conf <- c(0, 64, 96)
|
||||
|
||||
cat('if signed(power_in) > ', abs.level.int[1], ' then
|
||||
a <= std_logic_vector(to_unsigned(0, 7));\n');
|
||||
|
||||
last = abs.level.int[1]
|
||||
for(i in 2:length(abs.level.int)) {
|
||||
if(abs.level.int[i] == last) {
|
||||
next
|
||||
}
|
||||
last = abs.level.int[i];
|
||||
gdb = gain.levels[i]
|
||||
|
||||
lna.index = max(which(lna.level <= gdb))
|
||||
gdb = gdb - lna.level[lna.index]
|
||||
lna = lna.conf[lna.index]
|
||||
gdb = floor(gdb / 2)
|
||||
|
||||
cat('elsif signed(power_in) > ', last, ' then
|
||||
a <= std_logic_vector(to_unsigned(', lna + gdb, ', 7));\n');
|
||||
}
|
||||
|
||||
|
||||
# --if signed(power_in) > 2**24 then
|
||||
# -- a <= std_logic_vector(to_unsigned(0, 7));
|
||||
# --elsif signed(power_in) > 2**16 then
|
||||
# -- a <= std_logic_vector(to_unsigned(32, 7));
|
||||
# --else
|
||||
# -- a <= std_logic_vector(to_unsigned(127, 7));
|
||||
# --end if;
|
||||
Executable
+77
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python
|
||||
##################################################
|
||||
# Gnuradio Python Flow Graph
|
||||
# Title: Dc Offset
|
||||
# Generated: Sat Jan 3 17:36:59 2015
|
||||
##################################################
|
||||
|
||||
from gnuradio import blocks
|
||||
from gnuradio import eng_notation
|
||||
from gnuradio import gr
|
||||
from gnuradio import uhd
|
||||
from gnuradio.eng_option import eng_option
|
||||
from gnuradio.filter import firdes
|
||||
from optparse import OptionParser
|
||||
import time
|
||||
|
||||
class dc_offset(gr.top_block):
|
||||
|
||||
def __init__(self, dc=0):
|
||||
gr.top_block.__init__(self, "Dc Offset")
|
||||
|
||||
##################################################
|
||||
# Parameters
|
||||
##################################################
|
||||
self.dc = dc
|
||||
|
||||
##################################################
|
||||
# Variables
|
||||
##################################################
|
||||
self.samp_rate = samp_rate = 1000000
|
||||
|
||||
##################################################
|
||||
# Blocks
|
||||
##################################################
|
||||
self.uhd_usrp_sink_0 = uhd.usrp_sink(
|
||||
",".join(("", "")),
|
||||
uhd.stream_args(
|
||||
cpu_format="fc32",
|
||||
channels=range(1),
|
||||
),
|
||||
)
|
||||
self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
|
||||
self.uhd_usrp_sink_0.set_center_freq(2.41e9, 0)
|
||||
self.uhd_usrp_sink_0.set_gain(0, 0)
|
||||
self.uhd_usrp_sink_0.set_dc_offset(bool(dc), 0)
|
||||
self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*1)
|
||||
|
||||
##################################################
|
||||
# Connections
|
||||
##################################################
|
||||
self.connect((self.blocks_null_source_0, 0), (self.uhd_usrp_sink_0, 0))
|
||||
|
||||
|
||||
|
||||
def get_dc(self):
|
||||
return self.dc
|
||||
|
||||
def set_dc(self, dc):
|
||||
self.dc = dc
|
||||
|
||||
def get_samp_rate(self):
|
||||
return self.samp_rate
|
||||
|
||||
def set_samp_rate(self, samp_rate):
|
||||
self.samp_rate = samp_rate
|
||||
self.uhd_usrp_sink_0.set_samp_rate(self.samp_rate)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
|
||||
parser.add_option("", "--dc", dest="dc", type="intx", default=0,
|
||||
help="Set dc [default=%default]")
|
||||
(options, args) = parser.parse_args()
|
||||
tb = dc_offset(dc=options.dc)
|
||||
tb.start()
|
||||
raw_input('Press Enter to quit: ')
|
||||
tb.stop()
|
||||
tb.wait()
|
||||
Reference in New Issue
Block a user