commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8851 - in usrp2/branches/developers/roll-back-host-co


From: eb
Subject: [Commit-gnuradio] r8851 - in usrp2/branches/developers/roll-back-host-code/host: apps gr-usrp2 lib
Date: Wed, 9 Jul 2008 19:06:21 -0600 (MDT)

Author: eb
Date: 2008-07-09 19:06:20 -0600 (Wed, 09 Jul 2008)
New Revision: 8851

Added:
   usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.cc
   usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.h
   usrp2/branches/developers/roll-back-host-code/host/lib/pfring.c
   usrp2/branches/developers/roll-back-host-code/host/lib/pfring.h
   usrp2/branches/developers/roll-back-host-code/host/lib/ring.h
Removed:
   
usrp2/branches/developers/roll-back-host-code/host/apps/rx_streaming_samples2.cc
   
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_raw.cc
   
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_raw.h
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_table.cc
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_table.h
   usrp2/branches/developers/roll-back-host-code/host/lib/ring_buffer.h
   usrp2/branches/developers/roll-back-host-code/host/lib/sample_buffer.cc
   usrp2/branches/developers/roll-back-host-code/host/lib/sample_buffer.h
   usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic_thread.cc
   usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic_thread.h
   usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_tune_result.h
Modified:
   usrp2/branches/developers/roll-back-host-code/host/apps/
   usrp2/branches/developers/roll-back-host-code/host/apps/Makefile.am
   
usrp2/branches/developers/roll-back-host-code/host/apps/rx_streaming_samples.cc
   usrp2/branches/developers/roll-back-host-code/host/apps/streaming_fft.py
   usrp2/branches/developers/roll-back-host-code/host/apps/tx_samples.cc
   usrp2/branches/developers/roll-back-host-code/host/apps/u2_burn_mac_addr.cc
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/Makefile.am
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2.i
   
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.cc
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.h
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.cc
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.h
   
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.cc
   
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.h
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.cc
   usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.h
   usrp2/branches/developers/roll-back-host-code/host/lib/Makefile.am
   usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.cc
   usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.h
Log:
backed out 8507:8510 from host


Property changes on: usrp2/branches/developers/roll-back-host-code/host/apps
___________________________________________________________________
Name: svn:ignore
   - *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
.libs
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
find_usrps
rx_samples
tx_samples
gen_const
samples.dat
u2_burn_mac_addr
rx_streaming_samples
tx_samples_at_t
rx_streaming_samples2

   + *-stamp
*.a
*.bin
*.dump
*.log
*.rom
.deps
.libs
Makefile
Makefile.in
aclocal.m4
autom4te.cache
blink_leds
blink_leds2
build
compile
config.h
config.h.in
config.log
config.status
configure
depcomp
eth_test
gen_eth_packets
ibs_rx_test
ibs_tx_test
install-sh
libtool
ltmain.sh
missing
py-compile
rcv_eth_packets
run_tests.sh
stamp-h1
test1
test_phy_comm
timer_test
buf_ram_test
buf_ram_zero
hello
find_usrps
rx_samples
tx_samples
gen_const
samples.dat
u2_burn_mac_addr
rx_streaming_samples
tx_samples_at_t


Modified: usrp2/branches/developers/roll-back-host-code/host/apps/Makefile.am
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/apps/Makefile.am 
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/apps/Makefile.am 
2008-07-10 01:06:20 UTC (rev 8851)
@@ -26,7 +26,6 @@
 bin_PROGRAMS = \
        find_usrps \
        rx_streaming_samples \
-       rx_streaming_samples2 \
        tx_samples \
        gen_const \
        u2_burn_mac_addr
@@ -34,7 +33,6 @@
 find_usrps_SOURCES = find_usrps.cc
 # rx_samples_SOURCES = rx_samples.cc
 rx_streaming_samples_SOURCES = rx_streaming_samples.cc
-rx_streaming_samples2_SOURCES = rx_streaming_samples2.cc
 tx_samples_SOURCES = tx_samples.cc
 # tx_samples_at_t = tx_samples_at_t.cc
 gen_const_SOURCES = gen_const.cc

Modified: 
usrp2/branches/developers/roll-back-host-code/host/apps/rx_streaming_samples.cc
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/apps/rx_streaming_samples.cc 
    2008-07-10 00:42:03 UTC (rev 8850)
+++ 
usrp2/branches/developers/roll-back-host-code/host/apps/rx_streaming_samples.cc 
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -220,8 +220,7 @@
   int    ch;
   double tmp;
   u2_mac_addr_t mac_addr;
-  bool default_mac = true;
-  
+
   // setvbuf(stdout, 0, _IOFBF, 64 * 1024); // make stdout fully buffered
 
   while ((ch = getopt(argc, argv, "he:m:o:f:d:N:F:S:g:")) != EOF){
@@ -238,7 +237,6 @@
        usage(argv[0]);
        exit(1);
       }
-      default_mac = false;
       break;
 
     case 'o':
@@ -314,49 +312,64 @@
     }
   }
 
-  if (default_mac == true) {
-    op_id_reply_t r;
-    if (!usrp2_basic::pick_default_usrp(interface, &r)) {
-      std::cerr << "No default USRP2 found.\n";
-      return 1;
-    }
-    mac_addr = r.addr;
+  usrp2_basic *u2 = new usrp2_basic();
+
+  if (!u2->open(interface)){
+    std::cerr << "couldn't open " << interface << std::endl;
+    return 0;
   }
-    
-  usrp2_basic_sptr u2 = usrp2_make_basic(interface, mac_addr);
+
+  install_sig_handler(SIGINT, sig_handler);
   
-  install_sig_handler(SIGINT, sig_handler);
+  std::vector<op_id_reply_t> r = u2->find_usrps();
+
+  for (size_t i = 0; i < r.size(); i++){
+    std::cerr << r[i] << std::endl;
+  }
+
+  if (r.size() == 0){
+    std::cerr << "No USRP2 found.\n";
+    return 1;
+  }
+
+  u2_mac_addr_t which = r[0].addr;     // pick the first one
+
+
   gr_rt_status_t rt = gr_enable_realtime_scheduling();
   if (rt != RT_OK)
     std::cerr << "failed to enable realtime scheduling\n";
 
+
   // create writer thread
   class file_writer *writer = new file_writer(ofd, rb);
   writer->start_undetached();
+  
 
+  usrp2_tune_result tune_result;
+  
   if (gain != GAIN_NOT_SET){
-    if (!u2->set_rx_gain(gain)){
+    if (!u2->set_rx_gain(which, gain)){
       std::cerr << "set_rx_gain failed\n";
       return 1;
     }
   }
 
-  if (!(u2->set_rx_freq(freq, NULL))){
+  if (!u2->set_rx_freq(which, freq, &tune_result)){
     std::cerr << "set_rx_freq failed\n";
-    //return 1;
+    return 1;
   }
 
-  if (!u2->set_rx_decim(decim)){
+  if (!u2->set_rx_decim(which, decim)){
     std::cerr << "set_rx_decim failed\n";
     return 1;
   }
 
-  if (!u2->set_rx_scale_iq(scale, scale)){
+  if (!u2->set_rx_scale_iq(which, scale, scale)){
     std::cerr << "set_rx_scale_iq failed\n";
     return 1;
   }
 
-  if (!u2->start_rx_streaming(samples_per_frame)){
+  if (!u2->start_rx_streaming(which, samples_per_frame)){
     std::cerr << "start_rx_streaming failed\n";
     return 1;
   }
@@ -370,7 +383,7 @@
     u2_eth_samples_t   pkt;
     
     // read samples
-    int n = u2->read_samples(&pkt);
+    int n = u2->read_samples(which, &pkt);
     if (n <= 0)
       break;
     
@@ -401,7 +414,7 @@
   // smp_wmb()
   rb->d_not_empty.post();      // wake up file writer 
   
-  if (!u2->stop_rx()){
+  if (!u2->stop_rx(which)){
     std::cerr << "stop_rx failed\n";
     return 1;
   }

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/apps/rx_streaming_samples2.cc

Modified: 
usrp2/branches/developers/roll-back-host-code/host/apps/streaming_fft.py
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/apps/streaming_fft.py    
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/apps/streaming_fft.py    
2008-07-10 01:06:20 UTC (rev 8851)
@@ -31,8 +31,6 @@
                       help="set fgpa decimation rate to DECIM 
[default=%default]")
     parser.add_option("-f", "--freq", type="eng_float", default=0.0,
                       help="set frequency to FREQ", metavar="FREQ")
-    parser.add_option("-g", "--gain", type="string", default=None,
-                      help="set gain to GAIN [default=%default]")
     parser.add_option("-W", "--waterfall", action="store_true", default=False,
                       help="Enable waterfall display")
     parser.add_option("-S", "--oscilloscope", action="store_true", 
default=False,
@@ -59,12 +57,8 @@
     if options.oscilloscope:
         display_type = '-S'
 
-    gain_clause = ''
-    if options.gain:
-        gain_clause = '-g ' + options.gain
-
-    cmd = "sudo %s/rx_streaming_samples2 -e %s -f %g -d %d -F %d %s -o 
/proc/self/fd/1 | %s/stdin_int32_fft.py %s -f %g -d %d" % (
-        path, options.eth, options.freq, options.decim, 
options.samples_per_frame, gain_clause,
+    cmd = "sudo %s/rx_streaming_samples -e %s -f %g -d %d -F %d -o 
/proc/self/fd/1 | %s/stdin_int32_fft.py %s -f %g -d %d" % (
+        path, options.eth, options.freq, options.decim, 
options.samples_per_frame,
         path, display_type, options.freq, options.decim)
 
     print cmd

Modified: usrp2/branches/developers/roll-back-host-code/host/apps/tx_samples.cc
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/apps/tx_samples.cc       
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/apps/tx_samples.cc       
2008-07-10 01:06:20 UTC (rev 8851)
@@ -78,8 +78,7 @@
   int    ch;
   double tmp;
   u2_mac_addr_t mac_addr;
-  bool default_mac = true;
-  
+
   while ((ch = getopt(argc, argv, "he:m:I:rf:i:F:S:g:")) != EOF){
     switch (ch){
 
@@ -94,7 +93,6 @@
        usage(argv[0]);
        return 1;
       }
-      default_mac = false;
       break;
 
     case 'I':
@@ -162,36 +160,47 @@
     return 1;
   }
 
-  if (default_mac == true) {
-    op_id_reply_t r;
-    if (!usrp2_basic::pick_default_usrp(interface, &r)) {
-      std::cerr << "Unable to find USRP2." << std::endl;
-      return 1;
-    }
-    mac_addr = r.addr;
+  usrp2_basic *u2 = new usrp2_basic();
+
+  if (!u2->open(interface)){
+    std::cerr << "couldn't open " << interface << std::endl;
+    return 1;
   }
-  
-  usrp2_basic_sptr u2 = usrp2_make_basic(interface, mac_addr);
+
+  std::vector<op_id_reply_t> r = u2->find_usrps();
+
+  for (size_t i = 0; i < r.size(); i++){
+    std::cout << r[i] << std::endl;
+  }
+
+  if (r.size() == 0){
+    std::cerr << "No USRP2 found.\n";
+    return 1;
+  }
+
+  u2_mac_addr_t which = r[0].addr;     // pick the first one
+
+
   usrp2_tune_result tune_result;
   
   if (gain != GAIN_NOT_SET){
-    if (!u2->set_tx_gain(gain)){
+    if (!u2->set_tx_gain(which, gain)){
       std::cerr << "set_tx_gain failed\n";
       return 1;
     }
   }
 
-  if (!u2->set_tx_freq(freq, &tune_result)){
+  if (!u2->set_tx_freq(which, freq, &tune_result)){
     std::cerr << "set_tx_freq failed\n";
     return 1;
   }
 
-  if (!u2->set_tx_interp(interp)){
+  if (!u2->set_tx_interp(which, interp)){
     std::cerr << "set_tx_interp failed\n";
     return 1;
   }
 
-  if (!u2->set_tx_scale_iq(scale, scale)){
+  if (!u2->set_tx_scale_iq(which, scale, scale)){
     std::cerr << "set_tx_scale_iq failed\n";
     return 1;
   }
@@ -216,7 +225,7 @@
 
     // FIXME if r < 9, pad to 9 for minimum packet size constraint
 
-    if (!u2->write_samples(&pkt, r))
+    if (!u2->write_samples(which, &pkt, r))
       break;
   }
 

Modified: 
usrp2/branches/developers/roll-back-host-code/host/apps/u2_burn_mac_addr.cc
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/apps/u2_burn_mac_addr.cc 
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/apps/u2_burn_mac_addr.cc 
2008-07-10 01:06:20 UTC (rev 8851)
@@ -77,9 +77,22 @@
     fprintf(stderr, "invalid mac address: %s\n", new_mac_addr_str);
     exit(1);
   }
+  
 
-  usrp2_basic_sptr u2 = usrp2_make_basic(interface, old_mac_addr);
-  if (!u2->burn_mac_addr(new_mac_addr)){
+  usrp2_basic *u2 = new usrp2_basic();
+
+  if (!u2->open(interface)){
+    std::cerr << "couldn't open " << interface << std::endl;
+    return 0;
+  }
+
+  if (!u2->find_usrp_by_mac(old_mac_addr, 0)){
+    std::cerr << "No USRP2 with address "
+             << old_mac_addr << " found.\n";
+    return 1;
+  }
+
+  if (!u2->burn_mac_addr(old_mac_addr, new_mac_addr)){
     std::cerr << "Failed to burn mac address\n";
     return 1;
   }
@@ -90,9 +103,8 @@
   ts.tv_nsec = 250000000;
   nanosleep(&ts, 0);
 
-
   // Now see if we can find it using it's new address
-  if (!usrp2_basic::find_usrp(interface, new_mac_addr, 0)){
+  if (!u2->find_usrp_by_mac(new_mac_addr, 0)){
     std::cerr << "Failed to find USRP2 using new address "
              << new_mac_addr << ".\n";
     return 1;

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/Makefile.am
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/Makefile.am     
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/Makefile.am     
2008-07-10 01:06:20 UTC (rev 8851)
@@ -26,9 +26,7 @@
        usrp2_sink_base.cc \
        usrp2_sink_c.cc \
        usrp2_source_base.cc \
-       usrp2_source_c.cc \
-       usrp2_source_raw.cc \
-       usrp2_table.cc
+       usrp2_source_c.cc
 
 libgr_usrp2_la_LIBADD = \
        ../lib/libusrp2.la
@@ -37,11 +35,7 @@
        usrp2_sink_base.h \
        usrp2_sink_c.h \
        usrp2_source_base.h \
-       usrp2_source_c.h \
-       usrp2_source_raw.h
-       
-noinst_HEADERS = \
-       usrp2_table.h
+       usrp2_source_c.h
 
 # Export C++ GNU Radio driver to Python via SWIG
 ourpythondir = $(grpythondir)

Modified: usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2.i
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2.i 
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2.i 
2008-07-10 01:06:20 UTC (rev 8851)
@@ -29,92 +29,69 @@
 #include "gnuradio_swig_bug_workaround.h"      // mandatory bug fix
 #include "usrp2_sink_c.h"
 #include "usrp2_source_c.h"
-#include "usrp2_source_raw.h"
 %}
 
 // ----------------------------------------------------------------
 
-class usrp2_source_base : public gr_sync_block {
+class usrp2_sink_base : public gr_sync_block {
 
 protected:
-  usrp2_source_base(const std::string &name, gr_io_signature_sptr 
output_signature) 
+  usrp2_sink_base(const std::string &name,
+                 gr_io_signature_sptr input_signature) 
     throw (std::runtime_error);
 
 public:
-  ~usrp2_source_base();
+  ~usrp2_sink_base();
 
-  bool set_gain(double gain);
-  bool set_freq(double frequency, usrp2_tune_result *result);
-  bool set_decim(int decimation_factor);
-  bool set_scale_iq(int scale_i, int scale_q);
-
-  float adc_rate() const;
-  int decim_rate() const;
 };
 
 // ----------------------------------------------------------------
 
-GR_SWIG_BLOCK_MAGIC(usrp2,source_c)
+class usrp2_source_base : public gr_sync_block {
 
-usrp2_source_c_sptr
-usrp2_make_source_c(const std::string &ifc="eth0", const std::string &mac="") 
-  throw (std::runtime_error);
-
-class usrp2_source_c : public usrp2_source_base {
-
 protected:
-  usrp2_source_c(const std::string &ifc, const std::string &mac);
+  usrp2_source_base(const std::string &name,
+                   gr_io_signature_sptr output_signature) 
+    throw (std::runtime_error);
 
 public:
-  ~usrp2_source_c();
+  ~usrp2_source_base();
 
 };
 
 // ----------------------------------------------------------------
 
-GR_SWIG_BLOCK_MAGIC(usrp2,source_raw)
+GR_SWIG_BLOCK_MAGIC(usrp2,sink_c)
 
-usrp2_source_raw_sptr
-usrp2_make_source_raw(const std::string &ifc="eth0", const std::string 
&mac="") 
-  throw (std::runtime_error);
+usrp2_sink_c_sptr
+usrp2_make_sink_c() throw (std::runtime_error);
 
-class usrp2_source_raw : public usrp2_source_base {
+class usrp2_sink_c : public usrp2_sink_base {
 
 protected:
-  usrp2_source_raw(const std::string &ifc, const std::string &mac);
+  usrp2_sink_c();
 
 public:
-  ~usrp2_source_raw();
+  ~usrp2_sink_c();
 
 };
 
 // ----------------------------------------------------------------
 
-class usrp2_sink_base : public gr_sync_block {
+GR_SWIG_BLOCK_MAGIC(usrp2,source_c)
 
-protected:
-  usrp2_sink_base(const std::string &name, gr_io_signature_sptr 
input_signature) 
-    throw (std::runtime_error);
-
-public:
-  ~usrp2_sink_base();
-
-};
-
-// ----------------------------------------------------------------
-
-GR_SWIG_BLOCK_MAGIC(usrp2,sink_c)
-
-usrp2_sink_c_sptr
-usrp2_make_sink_c(const std::string &ifc="eth0", const std::string &mac="") 
+usrp2_source_c_sptr
+usrp2_make_source_c(const std::string &ifc="eth0",
+                   const std::string &mac="") 
   throw (std::runtime_error);
 
-class usrp2_sink_c : public usrp2_sink_base {
+class usrp2_source_c : public usrp2_source_base {
 
 protected:
-  usrp2_sink_c(const std::string &ifc, const std::string &mac);
+  usrp2_source_c(const std::string &ifc,
+                const std::string &mac);
 
 public:
-  ~usrp2_sink_c();
+  ~usrp2_source_c();
 
 };

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.cc
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.cc  
    2008-07-10 00:42:03 UTC (rev 8850)
+++ 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.cc  
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -25,68 +25,21 @@
 #endif
 
 #include <usrp2_sink_base.h>
-#include <usrp2_table.h>
 #include <gr_io_signature.h>
-#include <iostream>
 
-#define USRP2_SINK_BASE_DEBUG 1
-
 usrp2_sink_base::usrp2_sink_base(const std::string &name,
-                                gr_io_signature_sptr input_signature,
-                                const std::string &ifc,
-                                const std::string &mac) 
+                                gr_io_signature_sptr input_signature) 
   throw (std::runtime_error)
   : gr_sync_block(name,
                  input_signature,
-                 gr_make_io_signature(0, 0, 0)),
-    d_u2(usrp2_basic_sptr())
+                 gr_make_io_signature(0, 0, 0))
 {
-  op_id_reply_t id;
-  
-  if (mac == "") {
-    if (!usrp2_basic::pick_default_usrp(ifc, &id))
-      throw std::runtime_error("Unable to pick default USRP2");
-  }
-  else {
-    u2_mac_addr_t addr;
-    if (!usrp2_basic::parse_mac_addr(mac, &addr))
-      throw std::runtime_error("Invalid MAC address");
-    
-    if (!usrp2_basic::find_usrp(ifc, addr, &id))
-      throw std::runtime_error("Unable to find specified USRP2.");
-  }
-  
-  if (USRP2_SINK_BASE_DEBUG)
-    std::cout << "usrp2_sink_base: using ifc=" << ifc 
-             << " mac=" << id.addr 
-             << " hw_rev=" << id.hw_rev << std::endl;
-  
-  if (!(d_u2 = find_or_create_usrp2_basic(ifc, id.addr)))
-    throw std::runtime_error("Unable to create usrp2_basic!");
 }
 
-bool
-usrp2_sink_base::start()
+usrp2_sink_base::~usrp2_sink_base ()
 {
-  if (USRP2_SINK_BASE_DEBUG)
-    std::cout << "usrp2_sink_base: start" << std::endl;
-  
-  return true;
 }
 
-bool
-usrp2_sink_base::stop()
-{
-  if (USRP2_SINK_BASE_DEBUG)
-    std::cout << "usrp2_sink_base: stop" << std::endl;
-
-  return true;
-}
-
-usrp2_sink_base::~usrp2_sink_base()
-{
-}
-
 int
 usrp2_sink_base::work(int noutput_items,
                      gr_vector_const_void_star &input_items,

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.h
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.h   
    2008-07-10 00:42:03 UTC (rev 8850)
+++ 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_base.h   
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -24,26 +24,20 @@
 #define INCLUDED_USRP2_SINK_BASE_H
 
 #include <gr_sync_block.h>
-#include <usrp2_basic.h>
 #include <stdexcept>
 
 class usrp2_sink_base : public gr_sync_block {
 
+private:
+
 protected:
   usrp2_sink_base(const std::string &name,
-                 gr_io_signature_sptr input_signature,
-                 const std::string &ifc = "eth0",
-                 const std::string &mac = "") 
+                 gr_io_signature_sptr input_signature) 
     throw (std::runtime_error);
   
-  usrp2_basic_sptr d_u2;
-
 public:
   ~usrp2_sink_base();
   
-  virtual bool start();
-  virtual bool stop();
-
   int work(int noutput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.cc
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.cc 
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.cc 
2008-07-10 01:06:20 UTC (rev 8851)
@@ -26,19 +26,18 @@
 
 #include <usrp2_sink_c.h>
 #include <gr_io_signature.h>
+#include <usrp_standard.h>
+#include <usrp_bytesex.h>
 
 usrp2_sink_c_sptr
-usrp2_make_sink_c(const std::string &ifc, const std::string &mac) 
-  throw (std::runtime_error)
+usrp2_make_sink_c() throw (std::runtime_error)
 {
-  return usrp2_sink_c_sptr(new usrp2_sink_c(ifc, mac));
+  return usrp2_sink_c_sptr(new usrp2_sink_c());
 }
 
-usrp2_sink_c::usrp2_sink_c(const std::string &ifc, const std::string &mac) 
-  throw (std::runtime_error)
+usrp2_sink_c::usrp2_sink_c() throw (std::runtime_error)
   : usrp2_sink_base("usrp2_sink_c",
-                   gr_make_io_signature(1, 1, sizeof(gr_complex)),
-                   ifc, mac)
+                   gr_make_io_signature(1, 1, sizeof(gr_complex)))
 {
 }
 

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.h
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.h  
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_sink_c.h  
2008-07-10 01:06:20 UTC (rev 8851)
@@ -29,19 +29,16 @@
 typedef boost::shared_ptr<usrp2_sink_c> usrp2_sink_c_sptr;
 
 usrp2_sink_c_sptr
-usrp2_make_sink_c(const std::string &ifc="eth0", const std::string &mac="") 
-  throw (std::runtime_error);
+usrp2_make_sink_c() throw (std::runtime_error);
 
 class usrp2_sink_c : public usrp2_sink_base {
-
 private:
+
   friend usrp2_sink_c_sptr
-  usrp2_make_sink_c(const std::string &ifc, const std::string &mac)
-    throw (std::runtime_error);
+  usrp2_make_sink_c() throw (std::runtime_error);
 
 protected:
-  usrp2_sink_c(const std::string &ifc="eth0", const std::string &mac="") 
-    throw (std::runtime_error);
+  usrp2_sink_c() throw (std::runtime_error);
 
 public:
   ~usrp2_sink_c();

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.cc
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.cc
    2008-07-10 00:42:03 UTC (rev 8850)
+++ 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.cc
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -25,14 +25,11 @@
 #endif
 
 #include <usrp2_source_base.h>
-#include <usrp2_table.h>
 #include <gr_io_signature.h>
 #include <iostream>
 
-#define USRP2_SOURCE_BASE_DEBUG 0
+#define USRP2_SOURCE_BASE_DEBUG 1
 
-#define SAMPLES_PER_PACKET 250
-
 usrp2_source_base::usrp2_source_base(const std::string &name,
                                     gr_io_signature_sptr output_signature,
                                     const std::string &ifc,
@@ -41,88 +38,43 @@
   : gr_sync_block(name,
                  gr_make_io_signature(0, 0, 0),
                  output_signature),
-    d_u2(usrp2_basic_sptr())
+    d_u2(0), d_addr()
 {
-  op_id_reply_t id;
+  std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
+  if (r.size() == 0)
+    throw std::runtime_error("No USRP2s found on interface.");
 
   if (mac == "") {
-    if (!usrp2_basic::pick_default_usrp(ifc, &id))
-      throw std::runtime_error("Unable to pick default USRP2");
+    if (r.size() > 1)
+      throw std::runtime_error("Must supply USRP2 MAC address when multiple 
devices are present");
+    d_addr = r[0].addr;
   }
   else {
     u2_mac_addr_t addr;
     if (!usrp2_basic::parse_mac_addr(mac, &addr))
       throw std::runtime_error("Invalid MAC address");
 
-    if (!usrp2_basic::find_usrp(ifc, addr, &id))
+    unsigned int i;
+    for (i = 0; i < r.size(); i++)
+      if (r[i].addr == addr) {
+       d_addr = addr;
+       break;
+      }
+    
+    if (i == r.size())
       throw std::runtime_error("Unable to find specified USRP2.");
   }
 
   if (USRP2_SOURCE_BASE_DEBUG)
-    std::cout << "usrp2_source_base: using ifc=" << ifc 
-             << " mac=" << id.addr 
-             << " hw_rev=" << id.hw_rev << std::endl;
+    std::cout << "usrp2_source_base: using ifc=" << ifc << " mac=" << d_addr 
<< std::endl;
 
-  if (!(d_u2 = find_or_create_usrp2_basic(ifc, id.addr)))
-    throw std::runtime_error("Unable to create usrp2_basic!");
+  // Now retrieve or make and return usrp2_basic object for MAC address in 
d_addr
 }
 
-bool
-usrp2_source_base::set_gain(double gain)
-{
-  return d_u2->set_rx_gain(gain);
-}
-
-bool
-usrp2_source_base::set_freq(double frequency, usrp2_tune_result *result) 
-{
-  return d_u2->set_rx_freq(frequency, result);
-}
-
-bool
-usrp2_source_base::set_decim(int decimation_factor)
-{
-  return d_u2->set_rx_decim(decimation_factor);
-}
-
-bool
-usrp2_source_base::set_scale_iq(int scale_i, int scale_q)
-{
-  return d_u2->set_rx_scale_iq(scale_i, scale_q);
-}
-
-float
-usrp2_source_base::adc_rate() const
-{
-  return d_u2->adc_rate();
-}
-
-int 
-usrp2_source_base::decim_rate() const
-{
-  return d_u2->rx_decim_rate();
-}
-
-bool
-usrp2_source_base::start()
-{
-  if (USRP2_SOURCE_BASE_DEBUG)
-    std::cout << "usrp2_source_base: start" << std::endl;
-
-  return d_u2->start_rx_streaming(SAMPLES_PER_PACKET);
-}
-
-bool
-usrp2_source_base::stop()
-{
-  if (USRP2_SOURCE_BASE_DEBUG)
-    std::cout << "usrp2_source_base: stop" << std::endl;
-
-  return d_u2->stop_rx();
-}
-
 usrp2_source_base::~usrp2_source_base ()
 {
+  if (d_u2)
+    delete d_u2;
 }
 
 int
@@ -130,14 +82,5 @@
                        gr_vector_const_void_star &input_items,
                        gr_vector_void_star &output_items)
 {
-  if (USRP2_SOURCE_BASE_DEBUG)
-    ::write(1, "w", 1);
-
-  uint32_t buffer[SAMPLES_PER_PACKET];
-  uint32_t flags = 0; // In the streaming mode that gr-usrp2 uses, these are 
ignored
-
-  int n = d_u2->rx_samples(std::min(noutput_items, SAMPLES_PER_PACKET), 
buffer, &flags);
-  copy_from_usrp2_buffer(buffer, output_items[0], n);
-
-  return n;
+  return noutput_items;
 }

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.h
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.h 
    2008-07-10 00:42:03 UTC (rev 8850)
+++ 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_base.h 
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -36,27 +36,15 @@
                    const std::string &mac = "")
     throw (std::runtime_error);
 
-  usrp2_basic_sptr d_u2;
-  
+  usrp2_basic *d_u2;
+  u2_mac_addr_t d_addr;
+
 public:
   ~usrp2_source_base();
   
-  virtual bool start();
-  virtual bool stop();
-
-  bool set_gain(double gain);
-  bool set_freq(double frequency, usrp2_tune_result *result);
-  bool set_decim(int decimation_factor);
-  bool set_scale_iq(int scale_i, int scale_q);
-
-  float adc_rate() const;
-  int decim_rate() const;
-  
   int work(int noutput_items,
           gr_vector_const_void_star &input_items,
           gr_vector_void_star &output_items);
-
-  virtual void copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples) 
= 0;
 };
 
 #endif /* INCLUDED_USRP2_SOURCE_BASE_H */

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.cc
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.cc   
    2008-07-10 00:42:03 UTC (rev 8850)
+++ 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.cc   
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -26,10 +26,7 @@
 
 #include <usrp2_source_c.h>
 #include <gr_io_signature.h>
-#include <iostream>
 
-#define USRP2_SOURCE_C_DEBUG 1
-
 usrp2_source_c_sptr
 usrp2_make_source_c(const std::string &ifc,
                    const std::string &mac) 
@@ -50,14 +47,3 @@
 usrp2_source_c::~usrp2_source_c()
 {
 }
-
-void
-usrp2_source_c::copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples)
-{
-  gr_complex *out = (gr_complex *)dst;
-  for (int i = 0; i < nsamples; i++) {
-    float re = (int16_t)(src[i] >> 16);
-    float im = (int16_t)(src[i] & 0xFFFF);
-    *out++ = gr_complex(re, im); 
-  }
-}

Modified: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.h
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.h    
    2008-07-10 00:42:03 UTC (rev 8850)
+++ 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_c.h    
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -46,8 +46,6 @@
 
 public:
   ~usrp2_source_c();
-
-  virtual void copy_from_usrp2_buffer(uint32_t *src, void *dst, int nsamples);
 };
 
 #endif /* INCLUDED_USRP2_SOURCE_C_H */

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_raw.cc

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_source_raw.h

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_table.cc

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/gr-usrp2/usrp2_table.h

Modified: usrp2/branches/developers/roll-back-host-code/host/lib/Makefile.am
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/lib/Makefile.am  
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/lib/Makefile.am  
2008-07-10 01:06:20 UTC (rev 8851)
@@ -22,27 +22,30 @@
 lib_LTLIBRARIES = \
        libusrp2.la
 
+noinst_LTLIBRARIES = \
+       libpfring.la
+
+
 libusrp2_la_SOURCES = \
        gri_ethernet.cc \
+       gri_ethernet_pfring.cc \
        gri_if_stats.cc \
        gri_pktfilter.cc \
-       sample_buffer.cc \
        strtod_si.c \
-       usrp2_basic.cc \
-       usrp2_basic_thread.cc
+       usrp2_basic.cc
 
+libpfring_la_SOURCES = \
+       pfring.c
+
 libusrp2_la_LIBADD = \
+       libpfring.la \
        $(GR_OMNITHREAD_LIBS)
 
 include_HEADERS = \
        gri_ethernet.h \
+       gri_ethernet_pfring.h \
        gri_if_stats.h \
        gri_pktfilter.h \
-       ring_buffer.h \
-       sample_buffer.h \
        strtod_si.h \
-       usrp2_tune_result.h \
-       usrp2_basic.h \
-       usrp2_basic_thread.h
+       usrp2_basic.h
 
-MOSTLYCLEANFILES = *~ *.loT

Copied: 
usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.cc 
(from rev 8407, usrp2/trunk/host/lib/gri_ethernet_pfring.cc)
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.cc   
                            (rev 0)
+++ 
usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.cc   
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -0,0 +1,239 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2007,2008 Free Software Foundation, Inc.
+ *
+ * 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/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gri_ethernet_pfring.h>
+#include <gri_pktfilter.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <net/if.h>
+#include <features.h>
+#include <netpacket/packet.h>
+#include <net/ethernet.h>
+#include <netinet/in.h>
+#include <errno.h>
+
+#include <linux/types.h>
+#include <linux/filter.h>      // packet filter
+
+#define HAVE_PCAP 1            // KLUDGE
+#include <pfring.h>
+
+
+#define get_ring() static_cast<pfring*>(d_ring_void)
+
+
+static int
+open_packet_socket (std::string ifname, int protocol)
+{
+  if (protocol == 0)
+    protocol = htons(ETH_P_ALL);
+
+  int fd = socket (PF_PACKET, SOCK_RAW, protocol);
+  if (fd == -1){
+    fprintf (stderr, "%s: socket: %s\n", ifname.c_str(), strerror (errno));
+    return -1;
+  }
+
+  // get interface index
+  struct ifreq ifr;
+  memset (&ifr, 0, sizeof(ifr));
+  strncpy (ifr.ifr_name, ifname.c_str(), sizeof (ifr.ifr_name));
+  int res = ioctl (fd, SIOCGIFINDEX, &ifr);
+  if (res != 0){
+    ::close (fd);
+    fprintf (stderr, "%s: SIOCGIFINDEX: %s\n", ifname.c_str(), 
strerror(errno));
+    return -1;
+  }
+  int ifindex = ifr.ifr_ifindex;
+
+  // bind to the specified interface
+  sockaddr_ll sa;
+  memset (&sa, 0, sizeof (sa));
+  sa.sll_family = AF_PACKET;
+  sa.sll_protocol = protocol;
+  sa.sll_ifindex = ifindex;
+  res = bind (fd, (struct sockaddr *)&sa, sizeof (sa));
+  if (res != 0){
+    ::close (fd);
+    fprintf (stderr, "%s: bind: %s\n", ifname.c_str(), strerror(errno));
+    return -1;
+  }
+  return fd;
+}
+
+
+static void
+extract_mac_addr (unsigned char *mac, const unsigned char *hwaddr)
+{
+  int  i;
+  for (i = 0; i < 6; i++)
+    mac[i] = 0xff;
+
+  i = 0;
+  for (int j = 0; j < 14; j++){
+    if (hwaddr[j] != 0xff){
+      mac[i++] = hwaddr[j];
+      if (i == 6)
+       return;
+    }
+  }
+}
+
+static bool
+get_mac_addr (std::string ifname, int fd, unsigned char *mac)
+{
+  struct ifreq ifr;
+  memset (&ifr, 0, sizeof(ifr));
+  strncpy (ifr.ifr_name, ifname.c_str(), sizeof (ifr.ifr_name));
+  int res = ioctl (fd, SIOCGIFHWADDR, &ifr);
+  if (res != 0){
+    fprintf (stderr, "%s: SIOCGIFHWADDR: %s\n", ifname.c_str(), 
strerror(errno));
+    return false;
+  }
+  else {
+    if (0){
+      for (unsigned i = 0; i < sizeof (ifr.ifr_hwaddr.sa_data); i++)
+       fprintf (stderr, "%02x", ifr.ifr_hwaddr.sa_data[i]);
+      fprintf (stderr, "\n");
+    }
+  }
+  extract_mac_addr (mac, (unsigned char *)ifr.ifr_hwaddr.sa_data);
+  return true;
+}
+
+
+int
+gri_ethernet_pfring::fd() const
+{
+  return get_ring()->fd;
+}
+
+
+gri_ethernet_pfring::gri_ethernet_pfring ()
+  : d_wr_fd(-1), d_ring_void(0) 
+{
+  memset(d_mac, 0, sizeof (d_mac));
+}
+
+gri_ethernet_pfring::~gri_ethernet_pfring ()
+{
+  close();
+}
+
+bool
+gri_ethernet_pfring::open (std::string ifname, int protocol)
+{
+  if (get_ring()){
+    fprintf (stderr, "gri_ethernet_pfring: already open\n");
+    return false;
+  }
+
+  // not promisc, not reentrant
+  d_ring_void = pfring_open(const_cast<char *>(ifname.c_str()), 0, 0);
+  if (!d_ring_void)
+    return false;
+
+  get_mac_addr (ifname, fd(), d_mac);
+
+  if (d_wr_fd != -1){
+    fprintf (stderr, "gri_ethernet: already open\n");
+    return false;
+  }
+  if ((d_wr_fd = open_packet_socket (ifname, protocol)) == -1){
+    return false;
+  }
+
+  return true;
+}
+
+bool
+gri_ethernet_pfring::close ()
+{
+  pfring_close(get_ring());
+  if (d_wr_fd != -1){
+    ::close(d_wr_fd);
+    d_wr_fd = -1;
+  }
+  return true;
+}
+
+int
+gri_ethernet_pfring::read_packet (void *buf, int buflen)
+{
+  struct pfring_pkthdr hdr;
+  int r = pfring_recv(get_ring(), (char *) buf, buflen, &hdr, 1);
+  if (r != 1)
+    return -1;
+  
+  if (hdr.caplen != hdr.len){
+    printf("hdr.caplen = %4d, hdr.len = %4d\n", hdr.caplen, hdr.len);
+  }
+
+  return hdr.caplen;
+}
+
+int
+gri_ethernet_pfring::read_packet_dont_block (void *buf, int buflen)
+{
+  struct pfring_pkthdr hdr;
+  int r = pfring_recv(get_ring(), (char *) buf, buflen, &hdr, 0);
+  if (r != 1)
+    return 0;
+  
+  if (hdr.caplen != hdr.len){
+    printf("hdr.caplen = %4d, hdr.len = %4d\n", hdr.caplen, hdr.len);
+  }
+
+  return hdr.caplen;
+}
+
+int
+gri_ethernet_pfring::write_packet (const void *buf, int buflen)
+{
+  int retval = send (d_wr_fd, buf, buflen, 0);
+  if (retval < 0){
+    if (errno == EINTR)
+      return write_packet (buf, buflen);
+
+    perror ("gri_ethernet_pfring:write_packet: send");
+    return -1;
+  }
+  return retval;
+}
+
+bool
+gri_ethernet_pfring::attach_pktfilter (gri_pktfilter *pf)
+{
+  struct sock_fprog filter;
+  filter.len = pf->d_len;
+  filter.filter = pf->d_inst;
+  
+  int r = setsockopt (fd(), SOL_SOCKET, SO_ATTACH_FILTER, &filter, sizeof 
(filter));
+  if (r < 0){
+    perror ("gri_ethernet_pfring:attach:  SO_ATTACH_FILTER");
+    return false;
+  }
+  return true;
+}
+

Copied: 
usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.h 
(from rev 8407, usrp2/trunk/host/lib/gri_ethernet_pfring.h)
===================================================================
--- 
usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.h    
                            (rev 0)
+++ 
usrp2/branches/developers/roll-back-host-code/host/lib/gri_ethernet_pfring.h    
    2008-07-10 01:06:20 UTC (rev 8851)
@@ -0,0 +1,105 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005,2007,2008 Free Software Foundation, Inc.
+ *
+ * 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_GRI_ETHERNET_PFRING_H
+#define INCLUDED_GRI_ETHERNET_PFRING_H
+
+#include <string>
+#include <vector>
+
+class gri_pktfilter;
+
+/*!
+ * \brief Read and write ethernet frames.
+ *
+ * This provides a low level interface to hardware that communicates
+ * via raw (non-IP) ethernet frames.
+ */
+class gri_ethernet_pfring {
+  unsigned char        d_mac[6];
+  int          d_wr_fd;
+
+public:
+  void         *d_ring_void;   // kludge to work around bad hygiene in pfring.h
+
+  gri_ethernet_pfring ();
+  ~gri_ethernet_pfring ();
+
+  /*!
+   * \param ifname ethernet interface name, e.g., "eth0"
+   * \param protocol is the ethertype protocol number in network order.
+   *    Use 0 to receive all protocols.
+   */
+  bool open (std::string ifname, int protocol);
+
+  bool close ();
+
+  /*!
+   * \brief attach packet filter to socket to restrict which packets read sees.
+   * \param pf the packet filter
+   */
+  bool attach_pktfilter (gri_pktfilter *pf);
+
+  /*!
+   * \brief return 6 byte string containing our MAC address
+   */
+  const unsigned char *mac () const { return d_mac; }
+
+  /*!
+   * \brief Return file descriptor associated with socket.
+   */
+  int fd () const;
+
+  /*!
+   * \brief Read packet from interface.
+   *
+   * \param buf                where to put the packet
+   * \param buflen     maximum length of packet in bytes (should be >= 1528)
+   *
+   * \returns number of bytes read or -1 if trouble.
+   *
+   * Returned packet includes 14-byte ethhdr
+   */
+  int read_packet (void *buf, int buflen);
+
+  /*!
+   * \brief Read packet from interface, but don't block waiting
+   *
+   * \param buf                where to put the packet
+   * \param buflen     maximum length of packet in bytes (should be >= 1528)
+   *
+   * \returns number of bytes read, -1 if trouble or 0 if nothing available.
+   *
+   * Returned packet includes 14-byte ethhdr
+   */
+  int read_packet_dont_block (void *buf, int buflen);
+
+  /*
+   * \brief Write ethernet packet to interface.
+   *
+   * \param buf                the packet to write
+   * \param buflen     length of packet in bytes
+   *
+   * \returns number of bytes written or -1 if trouble.
+   *
+   * Packet must begin with 14-byte ethhdr, but does not include the FCS.
+   */
+  int write_packet (const void *buf, int buflen);
+};
+
+#endif /* INCLUDED_GRI_ETHERNET_PFRING_H */

Copied: usrp2/branches/developers/roll-back-host-code/host/lib/pfring.c (from 
rev 8407, usrp2/trunk/host/lib/pfring.c)
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/lib/pfring.c             
                (rev 0)
+++ usrp2/branches/developers/roll-back-host-code/host/lib/pfring.c     
2008-07-10 01:06:20 UTC (rev 8851)
@@ -0,0 +1,450 @@
+/*
+ *
+ * (C) 2005-07 - Luca Deri <address@hidden>
+ *
+ *
+ * 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 2 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, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "pfring.h"
+
+// #define __USE_XOPEN2K
+#include <sys/types.h>
+#include <pthread.h>
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <sys/poll.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+#include <linux/if_ether.h>
+#include <linux/sockios.h>
+
+
+// #define RING_DEBUG
+
+/* ******************************* */
+
+unsigned long long rdtsc() {
+  unsigned long long a;
+  asm volatile("rdtsc":"=A" (a));
+  return(a);
+}
+
+/* ******************************* */
+
+int pfring_set_cluster(pfring *ring, u_int clusterId) {
+  return(ring ? setsockopt(ring->fd, 0, SO_ADD_TO_CLUSTER,
+                             &clusterId, sizeof(clusterId)): -1);
+}
+
+/* ******************************* */
+
+int pfring_remove_from_cluster(pfring *ring) {
+  return(ring ? setsockopt(ring->fd, 0, SO_REMOVE_FROM_CLUSTER, 
+                             NULL, 0) : -1);
+}
+
+/* ******************************* */
+
+int pfring_set_reflector(pfring *ring, char *reflectorDevice) {
+  return(ring ?
+        setsockopt(ring->fd, 0, SO_SET_REFLECTOR,
+                   &reflectorDevice, strlen(reflectorDevice)) : -1);
+}
+
+/* ******************************* */
+
+static int set_if_promisc(const char *device, int set_promisc) {
+  int sock_fd;
+  struct ifreq ifr;
+
+  if(device == NULL) return(-3);
+
+  sock_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+  if(sock_fd <= 0) return(-1);
+  
+  memset(&ifr, 0, sizeof(ifr));
+  strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name));
+  if(ioctl(sock_fd, SIOCGIFFLAGS, &ifr) == -1) {  
+    close(sock_fd);
+    return(-2);
+  }      
+
+  if(set_promisc) {
+    if((ifr.ifr_flags & IFF_PROMISC) == 0) ifr.ifr_flags |= IFF_PROMISC;
+  } else {
+    /* Remove promisc */
+    if((ifr.ifr_flags & IFF_PROMISC) != 0) ifr.ifr_flags &= ~IFF_PROMISC;    
+  }
+  
+  if(ioctl(sock_fd, SIOCSIFFLAGS, &ifr) == -1) 
+    return(-1);
+  
+  close(sock_fd);
+  return(0);
+}
+
+/* **************************************************** */
+
+pfring* pfring_open(char *device_name, u_int8_t promisc, u_int8_t _reentrant) {
+  int err = 0;
+  pfring *ring = (pfring*)malloc(sizeof(pfring));
+  
+  if(ring == NULL) 
+    return(NULL);
+  else
+    memset(ring, 0, sizeof(pfring));
+
+  ring->reentrant = _reentrant;
+  ring->fd = socket(PF_RING, SOCK_RAW, htons(ETH_P_ALL));
+
+#ifdef RING_DEBUG
+  printf("Open RING [fd=%d]\n", ring->fd);
+#endif
+
+  if(ring->fd > 0) {
+    struct sockaddr sa;
+    int             rc;
+    u_int memSlotsLen;
+
+    sa.sa_family   = PF_RING;
+    snprintf(sa.sa_data, sizeof(sa.sa_data), "%s", device_name);
+    rc = bind(ring->fd, (struct sockaddr *)&sa, sizeof(sa));
+
+    if(rc == 0) {
+      ring->buffer = (char *)mmap(NULL, PAGE_SIZE,
+                                      PROT_READ|PROT_WRITE,
+                                      MAP_SHARED,
+                                      ring->fd, 0);
+
+      if(ring->buffer == MAP_FAILED) {
+       printf("mmap() failed");
+       free(ring);
+       return (NULL);  
+      }
+
+      ring->slots_info = (FlowSlotInfo *)ring->buffer;
+      if(ring->slots_info->version != RING_FLOWSLOT_VERSION) {
+       printf("Wrong RING version: "
+              "kernel is %i, libpfring was compiled with %i\n",
+              ring->slots_info->version, RING_FLOWSLOT_VERSION);
+       free(ring); 
+       return (NULL);
+      }
+      memSlotsLen = ring->slots_info->tot_mem;
+      munmap(ring->buffer, PAGE_SIZE);
+
+      ring->buffer = (char *)mmap(NULL, memSlotsLen,
+                                PROT_READ|PROT_WRITE,
+                                MAP_SHARED, ring->fd, 0);
+
+      if(ring->buffer == MAP_FAILED) {
+       printf("mmap() failed");
+       free(ring);
+       return (NULL);
+      }
+
+      ring->slots_info   = (FlowSlotInfo *)ring->buffer;
+      ring->slots = (char *)(ring->buffer+sizeof(FlowSlotInfo));
+
+      /* Safety check */
+      if(ring->slots_info->remove_idx >= ring->slots_info->tot_slots)
+       ring->slots_info->remove_idx = 0;
+
+      ring->page_id = PAGE_SIZE, ring->slot_id = 0, ring->pkts_per_page = 0;
+
+      /* Set defaults */
+      ring->device_name = strdup(device_name);
+
+#ifdef RING_DEBUG
+      printf("RING (%s): tot_slots=%d/slot_len=%d/"
+            "insertIdx=%d/remove_idx=%d/dropped=%d\n",
+            device_name,
+            ring->slots_info->tot_slots,
+            ring->slots_info->slot_len,
+            ring->slots_info->insert_idx,
+            ring->slots_info->remove_idx,
+            ring->slots_info->tot_lost);
+#endif
+
+      if(promisc) {
+       if(set_if_promisc(device_name, 1) == 0)
+         ring->clear_promisc = 1;
+      }
+
+    } else {
+      close(ring->fd);
+      err = -1;
+    }
+  } else {
+    err = -1; 
+    free(ring);
+  }
+
+  if(err == 0) {
+    if(ring->reentrant)
+      pthread_spin_init(&ring->spinlock, PTHREAD_PROCESS_PRIVATE);    
+    return(ring);
+  } else    
+    return(NULL);
+}
+
+/* **************************************************** */
+
+void pfring_close(pfring *ring) {
+  if(!ring) return;
+
+  if(ring->buffer != NULL) {
+    munmap(ring->buffer, ring->slots_info->tot_mem);
+  }
+
+  if(ring->clear_promisc)
+    set_if_promisc(ring->device_name, 0);
+
+  free(ring->device_name);
+  close(ring->fd);
+  if(ring->reentrant)
+    pthread_spin_destroy(&ring->spinlock);
+  free(ring);
+}
+
+/* **************************************************** */
+
+int pfring_toggle_filtering_policy(pfring *ring, u_int8_t 
rules_default_accept_policy) {
+  return(ring ? setsockopt(ring->fd, 0, SO_TOGGLE_FILTER_POLICY, 
+                          &rules_default_accept_policy,
+                          sizeof(rules_default_accept_policy)): -1);
+
+}
+
+/* **************************************************** */
+
+int pfring_version(pfring *ring, u_int32_t *version) {
+  if(ring == NULL) 
+    return(-1);
+  else {
+    socklen_t len = sizeof(u_int32_t);
+    return(getsockopt(ring->fd, 0, SO_GET_RING_VERSION, version, &len));
+  }
+}
+
+/* **************************************************** */
+
+int pfring_get_filtering_rule_stats(pfring *ring, u_int16_t rule_id,
+                                   char* stats, u_int *stats_len) {
+  if((ring == NULL) || (*stats_len < sizeof(u_int16_t)))
+    return(-1);
+  else {
+    memcpy(stats, &rule_id, sizeof(u_int16_t));
+    return(getsockopt(ring->fd, 0,
+                     SO_GET_FILTERING_RULE_STATS,
+                     stats, stats_len));
+  }
+}
+
+/* **************************************************** */
+
+int pfring_get_hash_filtering_rule_stats(pfring *ring,
+                                        hash_filtering_rule* rule,
+                                        char* stats, u_int *stats_len) {
+  if(ring == NULL)
+    return(-1);
+  else {
+    char buffer[2048];
+    int rc;
+    u_int len;
+    
+    memcpy(buffer, rule, sizeof(hash_filtering_rule));
+    len = sizeof(buffer);
+    rc = getsockopt(ring->fd, 0,
+                   SO_GET_HASH_FILTERING_RULE_STATS,
+                   buffer, &len);
+    if(rc < 0) 
+      return(rc);
+    else {
+      *stats_len = min(*stats_len, rc);
+      memcpy(stats, buffer, *stats_len);
+      return(0);
+    }
+  }
+}
+
+/* **************************************************** */
+
+int pfring_add_filtering_rule(pfring *ring, filtering_rule* rule_to_add) {
+  int rc;
+
+  if((!rule_to_add) || (!ring)) return(-1);
+
+  /* Sanitize entry */
+  if(rule_to_add->core_fields.port_low > rule_to_add->core_fields.port_high)
+    rule_to_add->core_fields.port_low = rule_to_add->core_fields.port_high;
+  if(rule_to_add->core_fields.host_low > rule_to_add->core_fields.host_high)
+    rule_to_add->core_fields.host_low = rule_to_add->core_fields.host_high;
+  
+  if(rule_to_add->balance_id > rule_to_add->balance_pool)
+    rule_to_add->balance_id = 0;
+  
+  rc = setsockopt(ring->fd, 0, SO_ADD_FILTERING_RULE,
+                 rule_to_add, sizeof(filtering_rule));
+
+  return(rc);
+}
+
+/* **************************************************** */
+
+int pfring_enable_ring(pfring *ring) {
+  char dummy;
+
+  if(!ring) return(-1);
+  return(setsockopt(ring->fd, 0, SO_ACTIVATE_RING, &dummy, sizeof(dummy)));
+}
+
+/* **************************************************** */
+
+int pfring_remove_filtering_rule(pfring *ring, u_int16_t rule_id) {
+  int rc;
+
+  rc = ring ? setsockopt(ring->fd, 0, SO_REMOVE_FILTERING_RULE,
+                        &rule_id, sizeof(rule_id)): -1;
+
+  return(rc);
+}
+
+/* **************************************************** */
+
+int pfring_handle_hash_filtering_rule(pfring *ring, 
+                                     hash_filtering_rule* rule_to_add,
+                                     u_char add_rule) {
+  int rc;
+
+  if((!rule_to_add) || (!ring)) return(-1);
+
+  rc = setsockopt(ring->fd, 0, add_rule ? SO_ADD_FILTERING_RULE : 
SO_REMOVE_FILTERING_RULE,
+                 rule_to_add, sizeof(hash_filtering_rule));
+
+  return(rc);
+}
+
+/* **************************************************** */
+
+int pfring_set_sampling_rate(pfring *ring, u_int32_t rate /* 1 = no sampling 
*/) {
+  int rc;
+
+  rc = ring ? setsockopt(ring->fd, 0, SO_SET_SAMPLING_RATE,
+                        &rate, sizeof(rate)): -1;
+
+  return(rc);
+}
+
+/* ******************************* */
+
+int pfring_stats(pfring *ring, pfring_stat *stats) {
+  if(ring && stats) {
+    stats->recv = ring->slots_info->tot_read;
+    stats->drop = ring->slots_info->tot_lost;
+    return(1);
+  } else
+    return(0);
+}
+
+/* **************************************************** */
+
+int pfring_recv(pfring *ring, char* buffer, u_int buffer_len, 
+               struct pfring_pkthdr *hdr, u_char wait_for_incoming_packet) {
+  FlowSlot *slot;
+  u_int32_t queuedPkts;
+
+  if((ring == NULL) || (ring->buffer == NULL)) return(-1);
+
+ do_pfring_recv:
+  if(ring->reentrant)
+    pthread_spin_lock(&ring->spinlock);
+         
+  slot = 
(FlowSlot*)&ring->slots[ring->slots_info->remove_idx*ring->slots_info->slot_len];
+
+  if(ring->slots_info->tot_insert >= ring->slots_info->tot_read)
+    queuedPkts = ring->slots_info->tot_insert - ring->slots_info->tot_read;
+  else
+    queuedPkts = ring->slots_info->tot_slots + ring->slots_info->tot_insert - 
ring->slots_info->tot_read;
+
+  if(queuedPkts && (slot->slot_state == 1 /* There's a packet to read */)) {
+    char *bucket = (char*)&slot->bucket;
+    struct pfring_pkthdr *_hdr = (struct pfring_pkthdr*)bucket;
+    int bktLen = _hdr->caplen+_hdr->parsed_header_len;
+
+    if(bktLen > buffer_len) bktLen = buffer_len-1;
+      
+    if(buffer) {
+      memcpy(buffer, &bucket[sizeof(struct pfring_pkthdr)], bktLen);
+      bucket[bktLen] = '\0';
+    }
+
+    if(ring->slots_info->remove_idx >= (ring->slots_info->tot_slots-1)) {
+      ring->slots_info->remove_idx = 0;
+      ring->page_id = PAGE_SIZE, ring->slot_id = 0, ring->pkts_per_page = 0;
+    } else {
+      ring->slots_info->remove_idx++;
+      ring->pkts_per_page++, ring->slot_id += ring->slots_info->slot_len;
+    }
+      
+    if(hdr) memcpy(hdr, _hdr, sizeof(struct pfring_pkthdr));
+
+    ring->slots_info->tot_read++;
+    slot->slot_state = 0; /* Empty slot */
+    if(ring->reentrant) pthread_spin_unlock(&ring->spinlock);
+    return(1);
+  } else if(wait_for_incoming_packet) {
+    struct pollfd pfd;
+    int rc;
+
+    if(ring->reentrant) pthread_spin_unlock(&ring->spinlock);
+
+    /* Sleep when nothing is happening */
+    pfd.fd      = ring->fd;
+    pfd.events  = POLLIN|POLLERR;
+    pfd.revents = 0;
+
+#ifdef RING_DEBUG
+    printf("==>> poll [remove_idx=%u][insert_idx=%u][loss=%d][queuedPkts=%u]"
+          "[slot_state=%d][tot_insert=%u][tot_read=%u]\n",
+          ring->slots_info->remove_idx,
+          ring->slots_info->insert_idx,
+          ring->slots_info->tot_lost, 
+          queuedPkts, slot->slot_state,
+          ring->slots_info->tot_insert,
+          ring->slots_info->tot_read);
+#endif
+             
+    errno = 0;
+
+    rc = poll(&pfd, 1, -1);
+
+    ring->num_poll_calls++;
+
+    if(rc == -1)
+      return(-1);
+    else
+      goto do_pfring_recv;
+  }
+
+  return(-1); /* Not reached */
+}

Copied: usrp2/branches/developers/roll-back-host-code/host/lib/pfring.h (from 
rev 8407, usrp2/trunk/host/lib/pfring.h)
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/lib/pfring.h             
                (rev 0)
+++ usrp2/branches/developers/roll-back-host-code/host/lib/pfring.h     
2008-07-10 01:06:20 UTC (rev 8851)
@@ -0,0 +1,143 @@
+/*
+ *
+ * (C) 2005-07 - Luca Deri <address@hidden>
+ *
+ *
+ * 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 2 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, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _PFRING_H_
+#define _PFRING_H_
+
+#include <sys/types.h>
+
+#ifndef __USE_XOPEN2K
+typedef volatile int pthread_spinlock_t;
+extern int pthread_spin_init (pthread_spinlock_t *__lock, int __pshared) 
__THROW;
+
+/* Destroy the spinlock LOCK.  */
+extern int pthread_spin_destroy (pthread_spinlock_t *__lock) __THROW;
+
+/* Wait until spinlock LOCK is retrieved.  */
+extern int pthread_spin_lock (pthread_spinlock_t *__lock) __THROW;
+
+/* Release spinlock LOCK.  */
+extern int pthread_spin_unlock (pthread_spinlock_t *__lock) __THROW;
+#endif
+
+
+#include <stdio.h>
+#include <stdarg.h>
+#include <sys/types.h>
+
+#if 0
+//#ifndef HAVE_PCAP
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <sys/poll.h>
+#include <sys/socket.h>
+#include <linux/if.h>
+#include <linux/if_ether.h>
+#include <linux/sockios.h>
+#endif
+
+#include <arpa/inet.h>
+#include <sys/ioctl.h>
+
+#include <ring.h>
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/time.h>
+#include <time.h>
+#include <string.h>
+#include <pthread.h>
+
+
+#define PAGE_SIZE         4096
+
+#define POLL_SLEEP_STEP         10 /* ns = 0.1 ms */
+#define POLL_SLEEP_MIN        POLL_SLEEP_STEP
+#define POLL_SLEEP_MAX        1000 /* ns */
+#define POLL_QUEUE_MIN_LEN     500 /* # packets */
+
+#ifdef  __cplusplus
+extern "C" {
+#endif
+
+#ifdef SAFE_RING_MODE
+  static char staticBucket[2048];
+#endif
+
+  /* ********************************* */
+
+  typedef struct {
+    char *buffer, *slots, *device_name;
+    int  fd;
+    FlowSlotInfo *slots_info;
+    u_int page_id, slot_id, pkts_per_page;
+    u_int poll_sleep;
+    u_int8_t clear_promisc, reentrant;
+    u_long num_poll_calls;
+    pthread_spinlock_t spinlock;
+  } pfring;
+
+  typedef struct {
+    u_int64_t recv, drop;
+  } pfring_stat;
+
+  /* NOTE: keep 'struct pfring_pkthdr' in sync with 'struct pcap_pkthdr' 
(ring.h) */
+  struct pfring_pkthdr {
+    struct timeval ts;    /* time stamp */
+    u_int32_t caplen;     /* length of portion present */
+    u_int32_t len;        /* length this packet (off wire) */
+    struct pkt_parsing_info parsed_pkt; /* packet parsing info */
+    u_int16_t parsed_header_len; /* Extra parsing data before packet */
+  }; 
+
+  /* ********************************* */
+
+  int pfring_set_cluster(pfring *ring, u_int clusterId);
+  int pfring_remove_from_cluster(pfring *ring);
+  int pfring_set_reflector(pfring *ring, char *reflectorDevice);
+  pfring* pfring_open(char *device_name, u_int8_t promisc, u_int8_t reentrant);
+  void pfring_close(pfring *ring);
+  int pfring_stats(pfring *ring, pfring_stat *stats);
+  int pfring_recv(pfring *ring, char* buffer, u_int buffer_len, 
+                 struct pfring_pkthdr *hdr, u_char wait_for_incoming_packet);
+  int pfring_get_filtering_rule_stats(pfring *ring, u_int16_t rule_id,
+                                     char* stats, u_int *stats_len);
+  int pfring_get_hash_filtering_rule_stats(pfring *ring,
+                                        hash_filtering_rule* rule,
+                                        char* stats, u_int *stats_len);
+  int pfring_add_filtering_rule(pfring *ring, filtering_rule* rule_to_add);
+  int pfring_handle_hash_filtering_rule(pfring *ring,
+                                       hash_filtering_rule* rule_to_add,
+                                       u_char add_rule);
+  int pfring_enable_ring(pfring *ring);
+  int pfring_remove_filtering_rule(pfring *ring, u_int16_t rule_id);
+  int pfring_toggle_filtering_policy(pfring *ring, u_int8_t 
rules_default_accept_policy);
+  int pfring_version(pfring *ring, u_int32_t *version);
+  int pfring_set_sampling_rate(pfring *ring, u_int32_t rate /* 1 = no sampling 
*/);
+  
+#ifdef  __cplusplus
+}
+#endif
+
+#endif /* _PFRING_H_ */

Copied: usrp2/branches/developers/roll-back-host-code/host/lib/ring.h (from rev 
8407, usrp2/trunk/host/lib/ring.h)
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/lib/ring.h               
                (rev 0)
+++ usrp2/branches/developers/roll-back-host-code/host/lib/ring.h       
2008-07-10 01:06:20 UTC (rev 8851)
@@ -0,0 +1,284 @@
+/*
+ * Definitions for packet ring
+ *
+ * 2004-07 Luca Deri <address@hidden>
+ */
+#ifndef __RING_H
+#define __RING_H
+
+#define INCLUDE_MAC_INFO
+
+#ifdef INCLUDE_MAC_INFO
+#define SKB_DISPLACEMENT    14 /* Include MAC address information */
+#else
+#define SKB_DISPLACEMENT    0  /* Do NOT include MAC address information */
+#endif
+
+#define RING_MAGIC
+#define RING_MAGIC_VALUE             0x88
+#define RING_FLOWSLOT_VERSION           9
+
+/* Versioning */
+#define RING_VERSION                "3.7.4"
+#define RING_VERSION_NUM           0x030704
+
+/* Set */
+#define SO_ADD_TO_CLUSTER                99
+#define SO_REMOVE_FROM_CLUSTER           100
+#define SO_SET_REFLECTOR                 101
+#define SO_SET_STRING                    102
+#define SO_ADD_FILTERING_RULE            103
+#define SO_REMOVE_FILTERING_RULE         104
+#define SO_TOGGLE_FILTER_POLICY          105
+#define SO_SET_SAMPLING_RATE             106
+#define SO_ACTIVATE_RING                 107
+
+/* Get */
+#define SO_GET_RING_VERSION              110
+#define SO_GET_FILTERING_RULE_STATS      111
+#define SO_GET_HASH_FILTERING_RULE_STATS 112
+
+/* *********************************** */
+
+#define NO_VLAN ((u_int16_t)-1)
+
+struct pkt_parsing_info {
+  /* core fields (also used by NetFlow) */
+  u_int16_t eth_type;   /* Ethernet type */
+  u_int16_t vlan_id;    /* VLAN Id or NO_VLAN */
+  u_int8_t  l3_proto, ipv4_tos;   /* Layer 3 protocol/TOS */
+  u_int32_t ipv4_src, ipv4_dst;   /* IPv4 src/dst IP addresses */
+  u_int16_t l4_src_port, l4_dst_port; /* Layer 4 src/dst ports */
+  u_int8_t tcp_flags;   /* TCP flags (0 if not available) */
+  /* Offsets of L3/L4/payload elements */
+  u_int16_t eth_offset, vlan_offset, l3_offset, l4_offset, payload_offset; 
+};
+
+#ifndef HAVE_PCAP
+/* NOTE: keep 'struct pfring_pkthdr' in sync with 'struct pcap_pkthdr' 
(ring.h) */
+struct pcap_pkthdr {
+  struct timeval ts;    /* time stamp */
+  u_int32_t caplen;     /* length of portion present */
+  u_int32_t len;        /* length this packet (off wire) */
+  struct pkt_parsing_info parsed_pkt; /* packet parsing info */
+  u_int16_t parsed_header_len; /* Extra parsing data before packet */
+};
+#endif
+
+/* *********************************** */
+
+#define MAX_PLUGIN_ID   128
+
+/* ************************************************* */
+
+typedef struct {
+  u_int8_t  proto;                   /* Use 0 for 'any' protocol */
+  u_int16_t vlan_id;                 /* Use '0' for any vlan */
+  u_int32_t host_low, host_high;     /* User '0' for any host. This is applied 
to both source
+                                       and destination. */
+  u_int16_t port_low, port_high;     /* All ports between port_low...port_high
+                                       0 means 'any' port. This is applied to 
both source
+                                       and destination. This means that
+                                       (proto, sip, sport, dip, dport) matches 
the rule if
+                                       one in "sip & sport", "sip & dport" 
"dip & sport"
+                                       match. */  
+} filtering_rule_core_fields;
+
+/* ************************************************* */
+
+typedef struct {
+  char payload_pattern[32];         /* If strlen(payload_pattern) > 0, the 
packet payload
+                                      must match the specified pattern */
+  u_int16_t filter_plugin_id;       /* If > 0 identifies a plugin to which the 
datastructure
+                                      below will be passed for matching */
+  char      filter_plugin_data[64]; /* Opaque datastructure that is 
interpreted by the
+                                      specified plugin and that specifies a 
filtering
+                                      criteria to be checked for match. 
Usually this data
+                                      is re-casted to a more meaningful 
datastructure
+                                   */
+} filtering_rule_extended_fields;
+
+/* ************************************************* */
+
+typedef struct {
+  /* Plugin Action */
+  u_int16_t plugin_id; /* ('0'=no plugin) id of the plugin associated with 
this rule */
+} filtering_rule_plugin_action;
+
+typedef enum {
+  forward_packet_and_stop_rule_evaluation = 0,
+  dont_forward_packet_and_stop_rule_evaluation,
+  execute_action_and_continue_rule_evaluation
+} rule_action_behaviour;
+
+typedef struct {
+  u_int16_t rule_id;                 /* Rules are processed in order from 
lowest to higest id */
+  rule_action_behaviour rule_action; /* What to do in case of match */
+  u_int8_t balance_id, balance_pool; /* If balance_pool > 0, then pass the 
packet above only if the
+                                       (hash(proto, sip, sport, dip, dport) % 
balance_pool) 
+                                       = balance_id */
+  filtering_rule_core_fields     core_fields;
+  filtering_rule_extended_fields extended_fields;
+  filtering_rule_plugin_action   plugin_action;
+} filtering_rule;
+
+/* *********************************** */
+
+#define DEFAULT_RING_HASH_SIZE     4096
+
+/*
+ * The hashtable contains only perfect matches: no
+ * wildacards or so are accepted.
+*/
+typedef struct {
+  u_int16_t vlan_id;
+  u_int8_t  proto;
+  u_int32_t host_peer_a, host_peer_b;
+  u_int16_t port_peer_a, port_peer_b;
+
+  rule_action_behaviour rule_action; /* What to do in case of match */
+  filtering_rule_plugin_action plugin_action;  
+} hash_filtering_rule;
+
+/* ************************************************* */
+
+typedef struct _filtering_hash_bucket {
+  hash_filtering_rule           rule;
+  void                          *plugin_data_ptr; /* ptr to a *continuous* 
memory area
+                                                    allocated by the plugin */ 
 
+  u_int16_t                     plugin_data_ptr_len;
+  struct _filtering_hash_bucket *next;
+} filtering_hash_bucket;
+
+/* ************************************************* */
+
+#ifdef __KERNEL__
+
+typedef struct {
+  filtering_rule rule;
+#ifdef CONFIG_TEXTSEARCH
+  struct ts_config *pattern;
+#endif
+  struct list_head list;
+  
+  /* Plugin action */
+  void *plugin_data_ptr; /* ptr to a *continuous* memory area allocated by the 
plugin */  
+} filtering_rule_element;
+
+struct parse_buffer {
+  void      *mem;
+  u_int16_t  mem_len;
+};
+
+/* Plugins */
+/* Execute an action (e.g. update rule stats) */
+typedef int (*plugin_handle_skb)(filtering_rule_element *rule,       /* In 
case the match is on the list */
+                                filtering_hash_bucket *hash_bucket, /* In case 
the match is on the hash */
+                                struct pcap_pkthdr *hdr,
+                                struct sk_buff *skb,
+                                u_int16_t filter_plugin_id,
+                                struct parse_buffer 
*filter_rule_memory_storage);
+/* Return 1/0 in case of match/no match for the given skb */
+typedef int (*plugin_filter_skb)(filtering_rule_element *rule, 
+                                struct pcap_pkthdr *hdr,
+                                struct sk_buff *skb,
+                                struct parse_buffer 
**filter_rule_memory_storage);
+/* Get stats about the rule */
+typedef int (*plugin_get_stats)(filtering_rule_element *element,
+                               u_char* stats_buffer, u_int stats_buffer_len);
+
+struct pfring_plugin_registration {
+  u_int16_t plugin_id;
+  plugin_filter_skb pfring_plugin_filter_skb; /* Filter skb: 1=match, 0=no 
match */
+  plugin_handle_skb pfring_plugin_handle_skb;
+  plugin_get_stats  pfring_plugin_get_stats;
+};
+
+typedef int (*register_pfring_plugin)(struct pfring_plugin_registration *reg);
+typedef int (*unregister_pfring_plugin)(u_int16_t pfring_plugin_id);
+
+extern register_pfring_plugin get_register_pfring_plugin(void);
+extern unregister_pfring_plugin get_unregister_pfring_plugin(void);
+extern void set_register_pfring_plugin(register_pfring_plugin the_handler);
+extern void set_unregister_pfring_plugin(unregister_pfring_plugin the_handler);
+
+extern int do_register_pfring_plugin(struct pfring_plugin_registration *reg);
+extern int do_unregister_pfring_plugin(u_int16_t pfring_plugin_id);
+
+#endif
+
+/* *********************************** */
+
+enum cluster_type {
+  cluster_per_flow = 0,
+  cluster_round_robin
+};
+
+/* *********************************** */
+
+#define RING_MIN_SLOT_SIZE    (60+sizeof(struct pcap_pkthdr))
+#define RING_MAX_SLOT_SIZE    (1514+sizeof(struct pcap_pkthdr))
+
+#ifndef min
+#define min(a,b) ((a < b) ? a : b)
+#endif
+
+/* *********************************** */
+
+typedef struct flowSlotInfo {
+  u_int16_t version, sample_rate;
+  u_int32_t tot_slots, slot_len, data_len, tot_mem;
+
+  u_int64_t tot_pkts, tot_lost;
+  u_int64_t tot_insert, tot_read;
+  u_int32_t insert_idx, remove_idx;
+} FlowSlotInfo;
+
+/* *********************************** */
+
+typedef struct flowSlot {
+#ifdef RING_MAGIC
+  u_char     magic;      /* It must alwasy be zero */
+#endif
+  u_char     slot_state; /* 0=empty, 1=full   */
+  u_char     bucket;     /* bucket[bucketLen] */
+} FlowSlot;
+
+/* *********************************** */
+
+#ifdef __KERNEL__
+
+FlowSlotInfo* getRingPtr(void);
+int allocateRing(char *deviceName, u_int numSlots,
+                u_int bucketLen, u_int sampleRate);
+unsigned int pollRing(struct file *fp, struct poll_table_struct * wait);
+void deallocateRing(void);
+
+/* ************************* */
+
+typedef int (*handle_ring_skb)(struct sk_buff *skb, u_char recv_packet, u_char 
real_skb);
+extern handle_ring_skb get_skb_ring_handler(void);
+extern void set_skb_ring_handler(handle_ring_skb the_handler);
+extern void do_skb_ring_handler(struct sk_buff *skb,
+                               u_char recv_packet, u_char real_skb);
+
+typedef int (*handle_ring_buffer)(struct net_device *dev,
+                                 char *data, int len);
+extern handle_ring_buffer get_buffer_ring_handler(void);
+extern void set_buffer_ring_handler(handle_ring_buffer the_handler);
+extern int do_buffer_ring_handler(struct net_device *dev,
+                                 char *data, int len);
+
+#endif /* __KERNEL__  */
+
+/* *********************************** */
+
+#define PF_RING          27      /* Packet Ring */
+#define SOCK_RING        PF_RING
+
+/* ioctl() */
+#define SIORINGPOLL      0x8888
+
+/* *********************************** */
+
+#endif /* __RING_H */

Deleted: usrp2/branches/developers/roll-back-host-code/host/lib/ring_buffer.h

Deleted: usrp2/branches/developers/roll-back-host-code/host/lib/sample_buffer.cc

Deleted: usrp2/branches/developers/roll-back-host-code/host/lib/sample_buffer.h

Modified: usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.cc
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.cc       
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.cc       
2008-07-10 01:06:20 UTC (rev 8851)
@@ -1,6 +1,6 @@
 /* -*- c++ -*- */
 /*
- * Copyright 2007,2008 Free Software Foundation, Inc.
+ * Copyright 2007 Free Software Foundation, Inc.
  *
  * 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
@@ -20,16 +20,13 @@
 #include "config.h"
 #endif
 #include "usrp2_basic.h"
-#include "usrp2_basic_thread.h"
 #include "gri_ethernet.h"
+#include "gri_ethernet_pfring.h"       // FIXME
 #include "gri_pktfilter.h"
 #include <usrp2_types.h>
-#include <usrp2_eth_packet.h>
 #include <iostream>
-#include <stdexcept>
 #include <math.h>
-#include <time.h>
-#include <errno.h>
+#include <time.h>      // debug
 
 #ifdef HAVE_SYS_SELECT_H
 #include <sys/select.h>
@@ -39,22 +36,7 @@
 #include <unistd.h>
 #endif
 
-static void
-udelay(long usecs)
-{
-  struct timeval t;
-  t.tv_sec = 0;
-  t.tv_usec = usecs;
-  select(0, 0, 0, 0, &t);
-}
 
-#define USRP2_BASIC_DEBUG 0
-#if USRP2_BASIC_DEBUG
-#define DEBUG_LOG(x) ::write(2, x, 1)
-#else
-#define DEBUG_LOG(x)
-#endif
-
 /*
  * Note, this should be considered a first cut at getting
  * enough implemented to check out the h/w.  We will probably
@@ -70,60 +52,57 @@
 #define MAX_PKTLEN 1512          // biggest thing USRP2 can swallow
                           //   (14-byte ethernet hdr + 1500 byte payload)
 
-usrp2_tune_result::~usrp2_tune_result()
+
+usrp2_basic::usrp2_basic()
+  : d_ethernet(new GRI_ETHERNET()), d_pf(0), d_seqno(0), d_next_rid(0)
 {
+  assert(sizeof(u2_eth_samples_t) == (size_t) MAX_PKTLEN);
 }
 
-usrp2_basic_sptr 
-usrp2_make_basic(const std::string &ifc, const u2_mac_addr_t &addr)
+usrp2_basic::~usrp2_basic()
 {
-  return usrp2_basic_sptr(new usrp2_basic(ifc, addr));
+  delete d_pf;
+  delete d_ethernet;
 }
 
-usrp2_basic::usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr)
-  : d_ethernet(new gri_ethernet()), d_pf(0), d_seqno(0), d_next_rid(0),
-    d_rx_active(false), d_tx_active(false), d_thread(0), 
-    d_rx_samples(256 * (1<<10), 1000), d_tx_samples(256 * (1<<10), 1000)
+bool
+usrp2_basic::open(std::string ifname)
 {
-  if (USRP2_BASIC_DEBUG)
-    std::cerr << "usrp2_basic: constructor" << std::endl;
+  if (!d_ethernet->open(ifname, htons(U2_ETHERTYPE)))
+    return false;
 
-  op_id_reply_t r;
-  if (!usrp2_basic::find_usrp(ifc, addr, &r))
-    throw std::runtime_error("Unable to find specified USRP2.");
+  if (d_pf)
+    delete d_pf;
 
-  d_ethernet->open(ifc, htons(U2_ETHERTYPE));
-  d_pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE, 
d_ethernet->mac());
-  if (!d_ethernet->attach_pktfilter(d_pf))
-    throw std::runtime_error("Unable to attach packet filter.");
-  d_addr = addr;
+  if (1){
+    d_pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE, 
d_ethernet->mac());
+    if (!d_ethernet->attach_pktfilter(d_pf))
+      return false;
+  }
 
-  d_thread = new usrp2_basic_thread(this);
-  d_thread->start();
-
-  udelay(1000);        // block for 1ms to allow thread to start
+  return true;
 }
 
-usrp2_basic::~usrp2_basic()
+bool
+usrp2_basic::close()
 {
-  if (USRP2_BASIC_DEBUG)
-    std::cerr << "usrp2_basic: destructor" << std::endl;
-
-  delete d_pf;
-
-  d_ethernet->close();
-  delete d_ethernet;
-
-  d_thread->stop();
-  d_thread = 0; // pthread derived objects delete themselves
+  return d_ethernet->close();
 }
 
 // ------------------------------------------------------------------------
 
-// static
 std::vector<op_id_reply_t> 
-usrp2_basic::find_usrps(const std::string &ifc)
+usrp2_basic::find_usrps()
 {
+  static u2_mac_addr_t broadcast_mac_addr =
+    {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }};
+
+  std::vector<op_id_reply_t> result;
+  int  r;
+
+  uint8_t      pktbuf[MAX_PKTLEN];
+  memset(pktbuf, 0, sizeof(pktbuf));
+
   struct command {
     u2_eth_packet_t    h;
     op_id_t            op_id;
@@ -134,64 +113,39 @@
     op_id_reply_t      op_id_reply;
   };
 
-  int r, len;
-  command *c = 0;
-  std::vector<op_id_reply_t> result;
-  gri_ethernet *enet = 0;
-  gri_pktfilter *pf = 0;
-      
-  enet = new gri_ethernet();
-  if (!enet->open(ifc, htons(U2_ETHERTYPE)))
-    goto bail;
+  command      *c = (command *) pktbuf;
+  init_etf_hdrs(&c->h, broadcast_mac_addr, 0, CONTROL_CHAN, -1);
 
-  pf = gri_pktfilter::make_ethertype_inbound(U2_ETHERTYPE, enet->mac());
-  if (!enet->attach_pktfilter(pf))
-    goto bail;
-
-  static u2_mac_addr_t broadcast_mac_addr =
-    {{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }};
-
-  uint8_t pktbuf[MAX_PKTLEN];
-  memset(pktbuf, 0, sizeof(pktbuf));
-
-  c = (command *)pktbuf;
-  c->h.ehdr.ethertype = htons(U2_ETHERTYPE);
-  c->h.ehdr.dst = broadcast_mac_addr;
-  memcpy(&c->h.ehdr.src, enet->mac(), 6);
-  c->h.thdr.flags = 0;
-  c->h.thdr.seqno = 0;
-  c->h.thdr.ack = 0;
-  u2p_set_word0(&c->h.fixed, 0, CONTROL_CHAN);
-  u2p_set_timestamp(&c->h.fixed, -1);
   c->op_id.opcode = OP_ID;
   c->op_id.len = sizeof(op_id_t);
-  len = std::max((size_t) MIN_PKTLEN, sizeof(command));
-  if (enet->write_packet(c, len) != len)
+  int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
+  if (d_ethernet->write_packet(c, len) != len){
     goto bail;
+  }
 
   /*
    * Wait no longer than 10ms and read all packets available.
    */
   fd_set read_fds;
   FD_ZERO(&read_fds);
-  FD_SET(enet->fd(), &read_fds);
+  FD_SET(d_ethernet->fd(), &read_fds);
   struct timeval timeout;
   timeout.tv_sec = 0;
   timeout.tv_usec = 10 * 1000; // 10 ms
   
-  r = select(enet->fd()+1, &read_fds, 0, 0, &timeout);
+  r = select(d_ethernet->fd()+1, &read_fds, 0, 0, &timeout);
 
-  while(1) {
+  while(1){
     memset(pktbuf, 0, sizeof(pktbuf));
-    len = enet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
+    int len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
     if (len < 0){
       perror("usrp2_basic: read_packet_dont_block");
-      goto bail;
+      return result;
     }
     if (len == 0)
       break;
 
-    reply *rp = (reply *)pktbuf;
+    reply *rp = (reply *) pktbuf;
     if (u2p_chan(&rp->h.fixed) != CONTROL_CHAN)  // ignore
       continue;
     if (rp->op_id_reply.opcode != OP_ID_REPLY) // ignore
@@ -200,33 +154,29 @@
     result.push_back(rp->op_id_reply);
   }
 
-bail:
-  if (enet)
-    delete enet;
-  if (pf)
-    delete pf;
+ bail:
   return result;
 }
 
 // static
-bool
-usrp2_basic::pick_default_usrp(const std::string &ifc, op_id_reply_t *id)
+std::vector<op_id_reply_t> 
+usrp2_basic::find_usrps(const std::string &ifc)
 {
-  std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
-  if (r.size() != 1)
-    return false;
+  usrp2_basic *u2 = new usrp2_basic();
+  if (!u2 || !u2->open(ifc)) {
+    std::cerr << "Unable to open network interface: " << ifc << std::endl;
+    return std::vector<op_id_reply_t>(0);
+  }
 
-  if (id)
-    *id = r[0];
-
-  return true;
+  std::vector<op_id_reply_t> r = u2->find_usrps();
+  delete u2;
+  return r;
 }
 
-// static
 bool
-usrp2_basic::find_usrp(const std::string &ifc, const u2_mac_addr_t &addr, 
op_id_reply_t *u)
+usrp2_basic::find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u)
 {
-  std::vector<op_id_reply_t> r = usrp2_basic::find_usrps(ifc);
+  std::vector<op_id_reply_t> r = find_usrps();
   for (unsigned i = 0; i < r.size(); i++){
     if (r[i].addr == addr){
       if (u)
@@ -234,7 +184,6 @@
       return true;
     }
   }
-
   return false;
 }
 
@@ -245,7 +194,7 @@
  */
 
 bool
-usrp2_basic::set_rx_gain(double gain)
+usrp2_basic::set_rx_gain(const u2_mac_addr_t &which, double gain)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -257,7 +206,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_RX_V2;
   c->op.len = sizeof(op_config_rx_v2_t);
@@ -279,7 +228,8 @@
 }
 
 bool
-usrp2_basic::set_rx_freq(double freq, usrp2_tune_result *result)
+usrp2_basic::set_rx_freq(const u2_mac_addr_t &which, double freq,
+                        usrp2_tune_result *result)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -291,7 +241,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_RX_V2;
   c->op.len = sizeof(op_config_rx_v2_t);
@@ -306,15 +256,19 @@
   c->eop.len = sizeof(op_eop_t);
 
   int len = std::max((size_t) MIN_PKTLEN, sizeof(command));
-  if (d_ethernet->write_packet(c, len) == len) {
-    // FIXME: wait for corresponding reply, set tune result members
-  }
+  if (d_ethernet->write_packet(c, len) != len)
+    return false;
 
+  // FIXME wait for corresponding reply, etc.
+
+  if (result)
+    memset(result, 0, sizeof(*result));
+
   return true;
 }
 
 bool
-usrp2_basic::set_rx_decim(int decimation_factor)
+usrp2_basic::set_rx_decim(const u2_mac_addr_t &which, int decimation_factor)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -326,7 +280,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_RX_V2;
   c->op.len = sizeof(op_config_rx_v2_t);
@@ -344,12 +298,11 @@
 
   // FIXME wait for corresponding reply, etc.
 
-  d_rx_decim = decimation_factor;
   return true;
 }
 
 bool
-usrp2_basic::set_rx_scale_iq(int scale_i, int scale_q)
+usrp2_basic::set_rx_scale_iq(const u2_mac_addr_t &which, int scale_i, int 
scale_q)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -361,7 +314,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_RX_V2;
   c->op.len = sizeof(op_config_rx_v2_t);
@@ -383,7 +336,7 @@
 }
 
 bool
-usrp2_basic::start_rx_streaming(unsigned int items_per_frame)
+usrp2_basic::start_rx_streaming(const u2_mac_addr_t &which, unsigned int 
items_per_frame)
 {
   if (items_per_frame == 0)    // provide our default
     items_per_frame = 250;
@@ -398,7 +351,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_START_RX_STREAMING;
   c->op.len = sizeof(op_start_rx_streaming_t);
@@ -411,12 +364,11 @@
   if (d_ethernet->write_packet(c, len) != len)
     return false;
 
-  d_rx_active = true;
   return true;
 }
 
 bool
-usrp2_basic::stop_rx()
+usrp2_basic::stop_rx(const u2_mac_addr_t &which)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -427,7 +379,7 @@
   };
     
   command      *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op_stop_rx.opcode = OP_STOP_RX;
   c->op_stop_rx.len = sizeof(op_stop_rx_t);
@@ -435,7 +387,6 @@
   if (d_ethernet->write_packet(c, len) != len)
     return false;
 
-  d_rx_active = false;
   return true;
 }
 
@@ -446,7 +397,7 @@
  */
 
 bool
-usrp2_basic::set_tx_gain(double gain)
+usrp2_basic::set_tx_gain(const u2_mac_addr_t &which, double gain)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -458,7 +409,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_TX_V2;
   c->op.len = sizeof(op_config_tx_v2_t);
@@ -480,7 +431,8 @@
 }
 
 bool
-usrp2_basic::set_tx_freq(double freq, usrp2_tune_result *result)
+usrp2_basic::set_tx_freq(const u2_mac_addr_t &which, double freq,
+                        usrp2_tune_result *result)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -492,7 +444,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_TX_V2;
   c->op.len = sizeof(op_config_tx_v2_t);
@@ -519,7 +471,7 @@
 }
 
 bool
-usrp2_basic::set_tx_interp(int interpolation_factor)
+usrp2_basic::set_tx_interp(const u2_mac_addr_t &which, int 
interpolation_factor)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -531,7 +483,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_TX_V2;
   c->op.len = sizeof(op_config_tx_v2_t);
@@ -553,7 +505,7 @@
 }
 
 bool
-usrp2_basic::set_tx_scale_iq(int scale_i, int scale_q)
+usrp2_basic::set_tx_scale_iq(const u2_mac_addr_t &which, int scale_i, int 
scale_q)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -565,7 +517,7 @@
   };
 
   command *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_CONFIG_TX_V2;
   c->op.len = sizeof(op_config_tx_v2_t);
@@ -597,33 +549,33 @@
 }
 
 int
-usrp2_basic::read_raw_samples(u2_eth_samples_t *pkt, int nmax)
+usrp2_basic::read_raw_samples(const u2_mac_addr_t &which,
+                             u2_eth_samples_t *pkt)
 {
-  int nmaxbytes = (nmax == -1) ? sizeof(*pkt) : nmax*sizeof(uint32_t) + 
sizeof(u2_eth_packet_t);
-  int readsize = std::min(int(sizeof(*pkt)), nmaxbytes);
-  int len = d_ethernet->read_packet(pkt, readsize);
+  int len = d_ethernet->read_packet(pkt, sizeof(*pkt));
+  // printf("read_packet = %d\n", len);
 
   if (len <= 0)
     return len;
 
   // FIXME check channel
 
-  if ((size_t) len < sizeof(u2_eth_packet_t)) {
-    fprintf(stderr, "usrp2_basic::read_raw_samples: short read, len=%d\n", 
len);
+
+  // shouldn't happen
+  if ((size_t) len < sizeof(u2_eth_packet_t))
     return 0;
-  }   
 
+  // convert to samples
   int r = (len - sizeof(u2_eth_packet_t)) / sizeof(uint32_t);
-  if (USRP2_BASIC_DEBUG)
-    fprintf(stderr, "usrp2_basic::read_raw_samples: nmax=%d nmaxbytes=%d 
readsize=%d len=%d r=%d\n", 
-           nmax, nmaxbytes, readsize, len, r);
+  // printf("read_raw_samples = %d\n", r);
   return r;
 }
 
 int
-usrp2_basic::read_samples(u2_eth_samples_t *pkt, int nmax)
+usrp2_basic::read_samples(const u2_mac_addr_t &which,
+                         u2_eth_samples_t *pkt)
 {
-  int r = read_raw_samples(pkt, nmax);
+  int r = read_raw_samples(which, pkt);
 
 #ifndef WORDS_BIGENDIAN
   for (int i = 0; i < r; i++)
@@ -636,12 +588,13 @@
 // ------------------------------------------------------------------------
 
 bool
-usrp2_basic::write_raw_samples(u2_eth_samples_t *pkt, size_t nsamples)
+usrp2_basic::write_raw_samples(const u2_mac_addr_t &which,
+                              u2_eth_samples_t *pkt, size_t nsamples)
 {
   if (nsamples > U2_MAX_SAMPLES)
     return false;
   
-  init_et_hdrs(&pkt->hdrs, d_addr);
+  init_et_hdrs(&pkt->hdrs, which);
 
   size_t len = sizeof(u2_eth_packet_t) + nsamples * sizeof(uint32_t);
   int n = d_ethernet->write_packet(pkt, len);
@@ -655,19 +608,21 @@
 }
 
 bool
-usrp2_basic::write_samples(u2_eth_samples_t *pkt, size_t nsamples)
+usrp2_basic::write_samples(const u2_mac_addr_t &which,
+                          u2_eth_samples_t *pkt, size_t nsamples)
 {
 #ifndef WORDS_BIGENDIAN
   for (size_t i = 0; i < nsamples; i++)
     pkt->samples[i] = htonl(pkt->samples[i]);
 #endif  
 
-  return write_raw_samples(pkt, nsamples);
+  return write_raw_samples(which, pkt, nsamples);
 }
 
 
 bool
-usrp2_basic::burn_mac_addr(const u2_mac_addr_t &new_addr)
+usrp2_basic::burn_mac_addr(const u2_mac_addr_t &which,
+                          const u2_mac_addr_t &new_addr)
 {
   uint8_t      pktbuf[MAX_PKTLEN];
   memset(pktbuf, 0, sizeof(pktbuf));
@@ -678,7 +633,7 @@
   };
     
   command      *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_BURN_MAC_ADDR;
   c->op.len = sizeof(op_burn_mac_addr_t);
@@ -746,7 +701,7 @@
 
 
 bool
-usrp2_basic::read_time(uint32_t *time)
+usrp2_basic::read_time(const u2_mac_addr_t &which, uint32_t *time)
 {
   *time = 0;
 
@@ -759,7 +714,7 @@
   };
     
   command      *c = (command *) pktbuf;
-  init_etf_hdrs(&c->h, d_addr, 0, CONTROL_CHAN, -1);
+  init_etf_hdrs(&c->h, which, 0, CONTROL_CHAN, -1);
 
   c->op.opcode = OP_READ_TIME;
   c->op.len = sizeof(op_read_time_t);
@@ -836,97 +791,3 @@
   return memcmp(&a, &b, sizeof(u2_mac_addr_t)) == 0;
 }
 
-void usrp2_basic::loop_body()
-{
-  fd_set read_fds, write_fds;
-  FD_ZERO(&read_fds);
-  FD_ZERO(&write_fds);
-
-  FD_SET(d_ethernet->fd(), &read_fds);
-
-  if (d_tx_active)
-    FD_SET(d_ethernet->fd(), &write_fds);
-    
-  struct timeval timeout;
-  timeout.tv_sec = 0;
-  timeout.tv_usec = 100 * 1000;        // 100 ms
-
-  DEBUG_LOG("S"); // select
-  int r = select(d_ethernet->fd()+1, &read_fds, &write_fds, 0, &timeout);
-  if (r > 0) {       // Socket available for read or for write
-    if (FD_ISSET(d_ethernet->fd(), &read_fds)) {
-      DEBUG_LOG("r"); // data to read()
-      rx_frames();
-    }
-    
-    if (FD_ISSET(d_ethernet->fd(), &write_fds)) {
-      DEBUG_LOG("w"); // can write()
-      tx_frames();
-    }
-  }
-  else if (r == 0) { 
-    DEBUG_LOG("T");   // socket timeout
-    return;
-  }
-  else {         
-    if (errno == EINTR)
-      DEBUG_LOG("I"); // interrupted system call
-    else
-      DEBUG_LOG("!"); // error on socket
-    return;
-  }
-}
-
-void
-usrp2_basic::rx_frames()
-{
-  uint8_t pktbuf[MAX_PKTLEN];
-  memset(pktbuf, 0, sizeof(pktbuf));
-
-  int len;
-  while (1) {
-    len = d_ethernet->read_packet_dont_block(pktbuf, sizeof(pktbuf));
-
-    if (len < 0) {
-      DEBUG_LOG("!"); // error
-      return;
-    } 
-    else if (len == 0) {
-      DEBUG_LOG("|"); // no more frames
-      return;
-    }
-    else if ((size_t)len < sizeof(u2_eth_packet_t)) {
-      DEBUG_LOG("<"); // short frame
-    }
-    else
-      DEBUG_LOG("R"); // rx ok
-
-    u2_eth_packet_t *p = (u2_eth_packet_t *)pktbuf;
-    if (u2p_chan(&p->fixed) == CONTROL_CHAN) {
-      DEBUG_LOG("-"); // ignore (FIXME: multiple channels, control channel)
-      continue;
-    }    
-
-    if (!d_rx_active)
-      continue;
-
-    u2_eth_samples_t *s = (u2_eth_samples_t *)pktbuf;
-    size_t plen = (len-sizeof(s->hdrs))/sizeof(uint32_t);
-    if (d_rx_samples.space_available() < plen) {
-      ::write(2, "uO", 2); // overrun
-      return;
-    }
-
-    d_rx_samples.write(plen, &s->samples[0], 0);
-  }   
-}
-
-void
-usrp2_basic::tx_frames()
-{
-}
-
-size_t usrp2_basic::rx_samples(size_t nmax, uint32_t *samples, uint32_t *flags)
-{
-  return d_rx_samples.read(nmax, samples, flags);
-}

Modified: usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.h
===================================================================
--- usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.h        
2008-07-10 00:42:03 UTC (rev 8850)
+++ usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic.h        
2008-07-10 01:06:20 UTC (rev 8851)
@@ -23,79 +23,78 @@
 #include <boost/shared_ptr.hpp>
 #include <vector>
 #include "usrp2_eth_packet.h"
-#include "usrp2_tune_result.h"
-#include "sample_buffer.h"
 
 class gri_ethernet;
+class gri_ethernet_pfring;
 class gri_pktfilter;
 
-class usrp2_basic;
-typedef boost::shared_ptr<usrp2_basic> usrp2_basic_sptr;
+#define GRI_ETHERNET gri_ethernet
 
-class usrp2_basic_thread;
+//! Provides detailed result of tuning request
 
-usrp2_basic_sptr usrp2_make_basic(const std::string &ifc, const u2_mac_addr_t 
&addr);
+struct usrp2_tune_result
+{
+  // RF frequency that corresponds to DC in the IF
+  double baseband_freq;
 
+  // frequency programmed into the DDC/DUC
+  double dxc_freq;
+
+  // residual frequency (typically < 0.01 Hz)
+  double residual_freq;
+
+  // is the spectrum inverted?
+  bool  spectrum_inverted;
+
+  usrp2_tune_result()
+    : baseband_freq(0), dxc_freq(0), residual_freq(0), 
spectrum_inverted(false) {}
+};
+
+
 class usrp2_basic : public boost::noncopyable
 {
-private:
-  friend usrp2_basic_sptr usrp2_make_basic(const std::string &ifc, const 
u2_mac_addr_t &addr);
-  friend class usrp2_basic_thread;
-  usrp2_basic(const std::string &ifc, const u2_mac_addr_t &addr);
-  
-  gri_ethernet *d_ethernet;
+  GRI_ETHERNET *d_ethernet;
   gri_pktfilter        *d_pf;
   int           d_seqno;
   int           d_next_rid;
-  u2_mac_addr_t  d_addr;
-  int            d_rx_decim;
-  bool           d_rx_active;
-  bool           d_tx_active;
-  
-  usrp2_basic_thread *d_thread;
-  sample_buffer   d_rx_samples;
-  sample_buffer   d_tx_samples;
-  
+
   void init_et_hdrs(u2_eth_packet_t *p, const u2_mac_addr_t &dst);
 
   void init_etf_hdrs(u2_eth_packet_t *p,
                     const u2_mac_addr_t &dst,
                     int word0_flags, int chan, uint32_t timestamp);
 
-  void loop_body();
-  void rx_frames();
-  void tx_frames();
-  
 public:
-  // ---- Static methods ----
+  usrp2_basic();
+  ~usrp2_basic();
 
   /*!
-   * \brief Return a vector that describes all usrps found on an interface.
-   * \param[in] ifc interface name, e.g., "eth0"
+   * \param ifname interface name, e.g., "eth0"
    */
+  bool open(std::string ifname = "eth0");
+  bool close();
+  
+  /*!
+   * Return a vector that describes all usrps found on already open'd interface
+   */
+  std::vector<op_id_reply_t> find_usrps();
+
+  /*!
+   * Return a vector that describes all usrps found on a specified interface.
+   */
   static std::vector<op_id_reply_t> find_usrps(const std::string &ifc);
 
   /*!
-   * \brief Find usrp by interface and mac address
+   * \brief Find usrp by mac address
    *
-   * \param[in] ifc interface name, e.g., "eth0"
    * \param[in] addr is the mac address of the USRP to look for
    * \param[out] u if not 0, is filled in with USRP info if found
    *
    * \returns true iff the specified usrp was found
    */
-  static bool find_usrp(const std::string &ifc, const u2_mac_addr_t &addr, 
op_id_reply_t *u);
+  bool find_usrp_by_mac(const u2_mac_addr_t &addr, op_id_reply_t *u);
 
   /*!
-   * \brief Find a default USRP2 on an interface
-   * \param[in] ifc interface name, e.g., "eth0"
-   * \param[out] id if not 0, is filled in with ID reply information if found
-   *
-   * \returns true iff a single USRP2 is enumerated on the bus
-   */
-  static bool pick_default_usrp(const std::string &ifc, op_id_reply_t *id);
-
-  /*!
    * \brief Parse short or long format mac address.
    *
    * \param[in]  s must be either HH:HH or HH:HH:HH:HH:HH:HH.
@@ -105,41 +104,60 @@
    */
   static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p);
 
-  // ---- Instance methods ----
 
-  ~usrp2_basic();
-
   /*
    * Rx configuration and control
    */
-  bool set_rx_gain(double gain);
-  bool set_rx_freq(double frequency, usrp2_tune_result *result);
-  bool set_rx_decim(int decimation_factor);
-  bool set_rx_scale_iq(int scale_i, int scale_q);
+  bool set_rx_gain(const u2_mac_addr_t &which, double gain);
+  bool set_rx_freq(const u2_mac_addr_t &which, double frequency, 
usrp2_tune_result *result);
+  bool set_rx_decim(const u2_mac_addr_t &which, int decimation_factor);
+  bool set_rx_scale_iq(const u2_mac_addr_t &which, int scale_i, int scale_q);
 
   //! start streaming Rx samples
-  bool start_rx_streaming(unsigned int items_per_frame=0);
+  bool start_rx_streaming(const u2_mac_addr_t &which, unsigned int 
items_per_frame=0);
 
   //! stop streaming Rx samples
-  bool stop_rx();
+  bool stop_rx(const u2_mac_addr_t &which);
 
-  int rx_decim_rate() const { return d_rx_decim; }
-
+  
   /*
    * Tx configuration and control
    */
-  bool set_tx_gain(double gain);
-  bool set_tx_freq(double frequency, usrp2_tune_result *result);
-  bool set_tx_interp(int interpolation_factor);
-  bool set_tx_scale_iq(int scale_i, int scale_q);
+  bool set_tx_gain(const u2_mac_addr_t &which, double gain);
+  bool set_tx_freq(const u2_mac_addr_t &which, double frequency, 
usrp2_tune_result *result);
+  bool set_tx_interp(const u2_mac_addr_t &which, int interpolation_factor);
+  bool set_tx_scale_iq(const u2_mac_addr_t &which, int scale_i, int scale_q);
   
+
+#if 0
+  bool start_rx(const u2_mac_addr_t &which,
+               double freq,
+               unsigned int decim,
+               unsigned int total_samples,     // 0 to begin streaming, or [9, 
2**21 - 1]
+               unsigned int samples_per_frame, // [9, 372] or [9, 506] if 
MTU==2034
+               int scale_i,                    // 16.0 fixed point format
+               int scale_q,                    // 16.0 fixed point format
+               bool rx_now = true,             // if true begin receiving now
+               uint32_t rx_time = -1           // otherwise begin receiving at 
rx_time
+               );
+
+
+  bool config_tx(const u2_mac_addr_t &which,
+                double freq,
+                unsigned int interp,
+                int scale_i,                   // 16.0 fixed point format
+                int scale_q                    // 16.0 fixed point format
+                );
+#endif
+
   /*!
    * \brief Read raw samples from USRP2.
    *
    * \param pkt contains the raw (non-endian corrected) samples
    * \returns number of valid samples in pkt.
    */
-  int read_raw_samples(u2_eth_samples_t *pkt, int nmax = -1);
+  int read_raw_samples(const u2_mac_addr_t &which,
+                      u2_eth_samples_t *pkt);
 
   /*!
    * \brief Read native-endian samples from USRP2.
@@ -147,7 +165,8 @@
    * \param pkt contains native-endian samples.
    * \returns number of valid samples in pkt.
    */
-  int read_samples(u2_eth_samples_t *pkt, int nmax = -1);
+  int read_samples(const u2_mac_addr_t &which,
+                  u2_eth_samples_t *pkt);
 
   /*!
    * \brief Write raw samples to USRP2.
@@ -160,7 +179,8 @@
    *
    * \returns true iff successful
    */
-  bool write_raw_samples(u2_eth_samples_t *pkt, size_t nsamples);
+  bool write_raw_samples(const u2_mac_addr_t &which,
+                        u2_eth_samples_t *pkt, size_t nsamples);
 
   /*!
    * \brief Write native-endian samples to USRP2.
@@ -173,43 +193,32 @@
    *
    * \returns true iff successful
    */
-  bool write_samples(u2_eth_samples_t *pkt, size_t nsamples);
+  bool write_samples(const u2_mac_addr_t &which,
+                    u2_eth_samples_t *pkt, size_t nsamples);
 
 
   /*!
-   * Receive at most nmax samples.  Returns number of samples actually read,
-   * and places the OR of the sample ranges into the flags variable.
-   *
-   * FIXME: multiple channels
-   */
-  size_t rx_samples(size_t nmax, uint32_t *samples, uint32_t *flags);
-
-  /*!
-   * Returns number of samples available for reading by rx_samples()
-   *
-   */
-  size_t items_available() const { return d_rx_samples.items_available(); }
-
-  /*!
    * \brief Read FPGA's idea of time
    *
    * N.B., this interface will probably change.
    * We're using it now for testing only.
    */
-  bool read_time(uint32_t *time);
+  bool read_time(const u2_mac_addr_t &which, uint32_t *time);
   
 
-  bool burn_mac_addr(const u2_mac_addr_t &new_addr);
+  bool burn_mac_addr(const u2_mac_addr_t &which,
+                    const u2_mac_addr_t &new_addr);
 
 
   //! Return frequency of master oscillator on USRP2.
-  long fpga_master_clock_freq () const { return 100000000; }   // 100e6
+  long  fpga_master_clock_freq () const { return 100000000; }  // 100e6
 
   //! Return A/D sample rate
   long adc_rate() const { return fpga_master_clock_freq(); }
 
   //! Return D/A sample rate
   long dac_rate() const { return fpga_master_clock_freq(); }
+
 };
 
 std::ostream& operator<<(std::ostream &os, const op_id_reply_t &x);

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic_thread.cc

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_basic_thread.h

Deleted: 
usrp2/branches/developers/roll-back-host-code/host/lib/usrp2_tune_result.h





reply via email to

[Prev in Thread] Current Thread [Next in Thread]