summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/chdr-dissector/.gitignore2
-rw-r--r--tools/chdr-dissector/CMakeLists.txt96
-rw-r--r--tools/chdr-dissector/cmake/Modules/FindGLIB2.cmake238
-rw-r--r--tools/chdr-dissector/cmake/Modules/FindWireshark.cmake28
-rwxr-xr-xtools/chdr-dissector/make-dissector-reg.py305
-rw-r--r--tools/chdr-dissector/moduleinfo.h9
-rw-r--r--tools/chdr-dissector/packet-chdr.c327
-rw-r--r--tools/chdr-dissector/plugin.rc.in34
-rw-r--r--tools/uhd_dump/Makefile23
-rw-r--r--tools/uhd_dump/chdr_log.c212
-rw-r--r--tools/uhd_dump/uhd_dump.c531
-rw-r--r--tools/uhd_dump/uhd_dump.h238
-rw-r--r--tools/uhd_dump/usrp3_regs.h51
13 files changed, 2094 insertions, 0 deletions
diff --git a/tools/chdr-dissector/.gitignore b/tools/chdr-dissector/.gitignore
new file mode 100644
index 000000000..0187b3dac
--- /dev/null
+++ b/tools/chdr-dissector/.gitignore
@@ -0,0 +1,2 @@
+build/
+*~
diff --git a/tools/chdr-dissector/CMakeLists.txt b/tools/chdr-dissector/CMakeLists.txt
new file mode 100644
index 000000000..8d19807d8
--- /dev/null
+++ b/tools/chdr-dissector/CMakeLists.txt
@@ -0,0 +1,96 @@
+# Copyright 2010-2013 Ettus Research LLC
+#
+# GNU Radio 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, or (at your option)
+# any later version.
+#
+# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+
+
+########################################################################
+# Project setup
+########################################################################
+cmake_minimum_required(VERSION 2.6)
+project(chdr-dissector C)
+set(chdr-dissector_VERSION_MAJOR 0)
+set(chdr-dissector_VERSION_MINOR 0)
+enable_testing()
+
+#select the release build type by default to get optimization flags
+if(NOT CMAKE_BUILD_TYPE)
+ set(CMAKE_BUILD_TYPE "Release")
+ message(STATUS "Build type not specified: defaulting to release.")
+endif(NOT CMAKE_BUILD_TYPE)
+set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")
+
+list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
+
+########################################################################
+# Compiler specific setup
+########################################################################
+#if(CMAKE_COMPILER_IS_GNUC AND NOT WIN32)
+# #http://gcc.gnu.org/wiki/Visibility
+# add_definitions(-fvisibility=visible)
+#endif()
+
+find_package(GLIB2)
+if(NOT GLIB2_FOUND)
+ message(FATAL_ERROR "Glib not found")
+endif()
+
+find_package(Wireshark)
+if(NOT WIRESHARK_FOUND)
+ message(FATAL_ERROR "Wireshark dev package not found")
+endif()
+
+
+########################################################################
+# Setup the include and linker paths
+########################################################################
+include_directories(
+ ${CMAKE_SOURCE_DIR}
+ ${GLIB2_INCLUDE_DIRS}
+ ${WIRESHARK_INCLUDE_DIRS}
+)
+
+#link_directories(
+# ${Boost_LIBRARY_DIRS}
+#)
+set(CMAKE_INSTALL_LIBDIR ~/.wireshark)
+
+# Set component parameters
+set(CHDR_DISSECTOR_INCLUDE_DIRS ${CMAKE_SOURCE_DIR} CACHE INTERNAL "" FORCE)
+
+set(CHDR_PLUGIN_SRC ${CMAKE_SOURCE_DIR}/packet-chdr.c)
+
+set(PLUGIN_C_GENERATOR ${CMAKE_SOURCE_DIR}/make-dissector-reg.py)
+set(PLUGIN_C plugin.c)
+
+add_custom_command(
+ OUTPUT ${PLUGIN_C}
+ DEPENDS ${CHDR_PLUGIN_SRC}
+ COMMAND ${PLUGIN_C_GENERATOR} ${CMAKE_SOURCE_DIR} plugin ${CHDR_PLUGIN_SRC}
+ COMMENT "Generating ${PLUGIN_C}"
+)
+
+add_library(chdr-plugin MODULE
+ ${PLUGIN_C}
+ moduleinfo.h
+ ${CHDR_PLUGIN_SRC}
+)
+set_target_properties(chdr-plugin PROPERTIES PREFIX "")
+set_target_properties(chdr-plugin PROPERTIES LINK_FLAGS "${WS_LINK_FLAGS}")
+target_link_libraries(chdr-plugin wireshark)
+
+install(TARGETS chdr-plugin
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/plugins NAMELINK_SKIP
+)
diff --git a/tools/chdr-dissector/cmake/Modules/FindGLIB2.cmake b/tools/chdr-dissector/cmake/Modules/FindGLIB2.cmake
new file mode 100644
index 000000000..ae7baddbb
--- /dev/null
+++ b/tools/chdr-dissector/cmake/Modules/FindGLIB2.cmake
@@ -0,0 +1,238 @@
+#
+# $Id: FindGLIB2.cmake 34248 2010-09-25 15:38:12Z jmayer $
+#
+# - Try to find GLib2
+# Once done this will define
+#
+# GLIB2_FOUND - system has GLib2
+# GLIB2_INCLUDE_DIRS - the GLib2 include directory
+# GLIB2_LIBRARIES - Link these to use GLib2
+#
+# HAVE_GLIB_GREGEX_H glib has gregex.h header and
+# supports g_regex_match_simple
+#
+# Copyright (c) 2006 Andreas Schneider <mail@cynapses.org>
+# Copyright (c) 2006 Philippe Bernery <philippe.bernery@gmail.com>
+# Copyright (c) 2007 Daniel Gollub <gollub@b1-systems.de>
+# Copyright (c) 2007 Alban Browaeys <prahal@yahoo.com>
+# Copyright (c) 2008 Michael Bell <michael.bell@web.de>
+# Copyright (c) 2008-2009 Bjoern Ricks <bjoern.ricks@googlemail.com>
+#
+# Redistribution and use is allowed according to the terms of the New
+# BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+
+IF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
+ # in cache already
+ SET(GLIB2_FOUND TRUE)
+ELSE (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS )
+
+ INCLUDE(FindPkgConfig)
+
+ ## Glib
+ IF ( GLIB2_FIND_REQUIRED )
+ SET( _pkgconfig_REQUIRED "REQUIRED" )
+ ELSE ( GLIB2_FIND_REQUIRED )
+ SET( _pkgconfig_REQUIRED "" )
+ ENDIF ( GLIB2_FIND_REQUIRED )
+
+ IF ( GLIB2_MIN_VERSION )
+ PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0>=${GLIB2_MIN_VERSION} )
+ ELSE ( GLIB2_MIN_VERSION )
+ PKG_SEARCH_MODULE( GLIB2 ${_pkgconfig_REQUIRED} glib-2.0 )
+ ENDIF ( GLIB2_MIN_VERSION )
+ IF ( PKG_CONFIG_FOUND )
+ IF ( GLIB2_FOUND )
+ SET ( GLIB2_CORE_FOUND TRUE )
+ ELSE ( GLIB2_FOUND )
+ SET ( GLIB2_CORE_FOUND FALSE )
+ ENDIF ( GLIB2_FOUND )
+ ENDIF ( PKG_CONFIG_FOUND )
+
+ # Look for glib2 include dir and libraries w/o pkgconfig
+ IF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
+ FIND_PATH(
+ _glibconfig_include_DIR
+ NAMES
+ glibconfig.h
+ PATHS
+ /opt/gnome/lib64
+ /opt/gnome/lib
+ /opt/lib/
+ /opt/local/lib
+ /sw/lib/
+ /usr/lib64
+ /usr/lib
+ /usr/local/include
+ ${CMAKE_LIBRARY_PATH}
+ PATH_SUFFIXES
+ glib-2.0/include
+ )
+
+ FIND_PATH(
+ _glib2_include_DIR
+ NAMES
+ glib.h
+ PATHS
+ /opt/gnome/include
+ /opt/local/include
+ /sw/include
+ /usr/include
+ /usr/local/include
+ PATH_SUFFIXES
+ glib-2.0
+ )
+
+ #MESSAGE(STATUS "Glib headers: ${_glib2_include_DIR}")
+
+ FIND_LIBRARY(
+ _glib2_link_DIR
+ NAMES
+ glib-2.0
+ glib
+ PATHS
+ /opt/gnome/lib
+ /opt/local/lib
+ /sw/lib
+ /usr/lib
+ /usr/local/lib
+ )
+ IF ( _glib2_include_DIR AND _glib2_link_DIR )
+ SET ( _glib2_FOUND TRUE )
+ ENDIF ( _glib2_include_DIR AND _glib2_link_DIR )
+
+
+ IF ( _glib2_FOUND )
+ SET ( GLIB2_INCLUDE_DIRS ${_glib2_include_DIR} ${_glibconfig_include_DIR} )
+ SET ( GLIB2_LIBRARIES ${_glib2_link_DIR} )
+ SET ( GLIB2_CORE_FOUND TRUE )
+ ELSE ( _glib2_FOUND )
+ SET ( GLIB2_CORE_FOUND FALSE )
+ ENDIF ( _glib2_FOUND )
+
+ # Handle dependencies
+ # libintl
+ IF ( NOT LIBINTL_FOUND )
+ FIND_PATH(LIBINTL_INCLUDE_DIR
+ NAMES
+ libintl.h
+ PATHS
+ /opt/gnome/include
+ /opt/local/include
+ /sw/include
+ /usr/include
+ /usr/local/include
+ )
+
+ FIND_LIBRARY(LIBINTL_LIBRARY
+ NAMES
+ intl
+ PATHS
+ /opt/gnome/lib
+ /opt/local/lib
+ /sw/lib
+ /usr/local/lib
+ /usr/lib
+ )
+
+ IF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
+ SET (LIBINTL_FOUND TRUE)
+ ENDIF (LIBINTL_LIBRARY AND LIBINTL_INCLUDE_DIR)
+ ENDIF ( NOT LIBINTL_FOUND )
+
+ # libiconv
+ IF ( NOT LIBICONV_FOUND )
+ FIND_PATH(LIBICONV_INCLUDE_DIR
+ NAMES
+ iconv.h
+ PATHS
+ /opt/gnome/include
+ /opt/local/include
+ /opt/local/include
+ /sw/include
+ /sw/include
+ /usr/local/include
+ /usr/include
+ PATH_SUFFIXES
+ glib-2.0
+ )
+
+ FIND_LIBRARY(LIBICONV_LIBRARY
+ NAMES
+ iconv
+ PATHS
+ /opt/gnome/lib
+ /opt/local/lib
+ /sw/lib
+ /usr/lib
+ /usr/local/lib
+ )
+
+ IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+ SET (LIBICONV_FOUND TRUE)
+ ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+ ENDIF ( NOT LIBICONV_FOUND )
+
+ IF (LIBINTL_FOUND)
+ SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBINTL_LIBRARY})
+ SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBINTL_INCLUDE_DIR})
+ ENDIF (LIBINTL_FOUND)
+
+ IF (LIBICONV_FOUND)
+ SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY})
+ SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR})
+ ENDIF (LIBICONV_FOUND)
+
+ ENDIF ( NOT GLIB2_FOUND AND NOT PKG_CONFIG_FOUND )
+ ##
+
+ IF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
+ SET (GLIB2_FOUND TRUE)
+ ENDIF (GLIB2_CORE_FOUND AND GLIB2_INCLUDE_DIRS AND GLIB2_LIBRARIES)
+
+ IF (GLIB2_FOUND)
+ IF (NOT GLIB2_FIND_QUIETLY)
+ MESSAGE (STATUS "Found GLib2: ${GLIB2_LIBRARIES} ${GLIB2_INCLUDE_DIRS}")
+ ENDIF (NOT GLIB2_FIND_QUIETLY)
+ ELSE (GLIB2_FOUND)
+ IF (GLIB2_FIND_REQUIRED)
+ MESSAGE (SEND_ERROR "Could not find GLib2")
+ ENDIF (GLIB2_FIND_REQUIRED)
+ ENDIF (GLIB2_FOUND)
+
+ # show the GLIB2_INCLUDE_DIRS and GLIB2_LIBRARIES variables only in the advanced view
+ MARK_AS_ADVANCED(GLIB2_INCLUDE_DIRS GLIB2_LIBRARIES)
+ MARK_AS_ADVANCED(LIBICONV_INCLUDE_DIR LIBICONV_LIBRARY)
+ MARK_AS_ADVANCED(LIBINTL_INCLUDE_DIR LIBINTL_LIBRARY)
+
+ENDIF (GLIB2_LIBRARIES AND GLIB2_INCLUDE_DIRS)
+
+IF ( WIN32 )
+ # include libiconv for win32
+ IF ( NOT LIBICONV_FOUND )
+ FIND_PATH(LIBICONV_INCLUDE_DIR iconv.h PATH_SUFFIXES glib-2.0)
+
+ FIND_LIBRARY(LIBICONV_LIBRARY NAMES iconv)
+
+ IF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+ SET (LIBICONV_FOUND TRUE)
+ ENDIF (LIBICONV_LIBRARY AND LIBICONV_INCLUDE_DIR)
+ ENDIF ( NOT LIBICONV_FOUND )
+ IF (LIBICONV_FOUND)
+ SET (GLIB2_LIBRARIES ${GLIB2_LIBRARIES} ${LIBICONV_LIBRARY})
+ SET (GLIB2_INCLUDE_DIRS ${GLIB2_INCLUDE_DIRS} ${LIBICONV_INCLUDE_DIR})
+ ENDIF (LIBICONV_FOUND)
+ENDIF ( WIN32 )
+
+IF ( GLIB2_FOUND )
+ # Check if system has a newer version of glib
+ # which supports g_regex_match_simple
+ INCLUDE( CheckIncludeFiles )
+ SET( CMAKE_REQUIRED_INCLUDES ${GLIB2_INCLUDE_DIRS} )
+ CHECK_INCLUDE_FILES ( glib/gregex.h HAVE_GLIB_GREGEX_H )
+ CHECK_INCLUDE_FILES ( glib/gchecksum.h HAVE_GLIB_GCHECKSUM_H )
+ # Reset CMAKE_REQUIRED_INCLUDES
+ SET( CMAKE_REQUIRED_INCLUDES "" )
+ENDIF( GLIB2_FOUND )
diff --git a/tools/chdr-dissector/cmake/Modules/FindWireshark.cmake b/tools/chdr-dissector/cmake/Modules/FindWireshark.cmake
new file mode 100644
index 000000000..59497da16
--- /dev/null
+++ b/tools/chdr-dissector/cmake/Modules/FindWireshark.cmake
@@ -0,0 +1,28 @@
+#
+# Try to find the wireshark library and its includes
+#
+# This snippet sets the following variables:
+# WIRESHARK_FOUND True if wireshark library got found
+# WIRESHARK_INCLUDE_DIRS Location of the wireshark headers
+# WIRESHARK_LIBRARIES List of libraries to use wireshark
+#
+# Copyright (c) 2011 Reinhold Kainhofer <reinhold@kainhofer.com>
+#
+# Redistribution and use is allowed according to the terms of the New
+# BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+#
+
+# wireshark does not install its library with pkg-config information,
+# so we need to manually find the libraries and headers
+
+FIND_PATH( WIRESHARK_INCLUDE_DIRS epan/column_info.h PATH_SUFFIXES wireshark )
+FIND_LIBRARY( WIRESHARK_LIBRARIES wireshark )
+
+# Report results
+IF ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS )
+ SET( WIRESHARK_FOUND 1 )
+ELSE ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS )
+ MESSAGE( SEND_ERROR "Could NOT find the wireshark library and headers" )
+ENDIF ( WIRESHARK_LIBRARIES AND WIRESHARK_INCLUDE_DIRS )
+
diff --git a/tools/chdr-dissector/make-dissector-reg.py b/tools/chdr-dissector/make-dissector-reg.py
new file mode 100755
index 000000000..44972909b
--- /dev/null
+++ b/tools/chdr-dissector/make-dissector-reg.py
@@ -0,0 +1,305 @@
+#!/usr/bin/env python
+#
+# Looks for registration routines in the protocol dissectors,
+# and assembles C code to call all the routines.
+#
+# This is a Python version of the make-reg-dotc shell script.
+# Running the shell script on Win32 is very very slow because of
+# all the process-launching that goes on --- multiple greps and
+# seds for each input file. I wrote this python version so that
+# less processes would have to be started.
+#
+# $Id: make-dissector-reg.py 30447 2009-10-09 20:47:18Z krj $
+
+import os
+import sys
+import re
+import pickle
+from stat import *
+
+VERSION_KEY = '_VERSION'
+CUR_VERSION = '$Id: make-dissector-reg.py 30447 2009-10-09 20:47:18Z krj $'
+
+#
+# The first argument is the directory in which the source files live.
+#
+srcdir = sys.argv[1]
+
+#
+# The second argument is either "plugin" or "dissectors"; if it's
+# "plugin", we build a plugin.c for a plugin, and if it's
+# "dissectors", we build a register.c for libwireshark.
+#
+registertype = sys.argv[2]
+if registertype == "plugin" or registertype == "plugin_wtap":
+ tmp_filename = "plugin.c-tmp"
+ final_filename = "plugin.c"
+ cache_filename = None
+ preamble = """\
+/*
+ * Do not modify this file.
+ *
+ * It is created automatically by Makefile or Makefile.nmake.
+ */
+"""
+elif registertype == "dissectors":
+ tmp_filename = "register.c-tmp"
+ final_filename = "register.c"
+ cache_filename = "register-cache.pkl"
+ preamble = """\
+/*
+ * Do not modify this file.
+ *
+ * It is created automatically by the "register.c" target in
+ * epan/dissectors/Makefile or Makefile.nmake using information in
+ * epan/dissectors/register-cache.pkl.
+ *
+ * You can force this file to be regenerated completely by deleting
+ * it along with epan/dissectors/register-cache.pkl.
+ */
+"""
+else:
+ print "Unknown output type '%s'" % registertype
+ sys.exit(1)
+
+
+#
+# All subsequent arguments are the files to scan.
+#
+files = sys.argv[3:]
+
+# Create the proper list of filenames
+filenames = []
+for file in files:
+ if os.path.isfile(file):
+ filenames.append(file)
+ else:
+ filenames.append(os.path.join(srcdir, file))
+
+if len(filenames) < 1:
+ print "No files found"
+ sys.exit(1)
+
+
+# Look through all files, applying the regex to each line.
+# If the pattern matches, save the "symbol" section to the
+# appropriate array.
+regs = {
+ 'proto_reg': [],
+ 'handoff_reg': [],
+ 'wtap_register': [],
+ }
+
+# For those that don't know Python, r"" indicates a raw string,
+# devoid of Python escapes.
+proto_regex0 = r"^(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+proto_regex1 = r"void\s+(?P<symbol>proto_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+handoff_regex0 = r"^(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
+handoff_regex1 = r"void\s+(?P<symbol>proto_reg_handoff_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+wtap_reg_regex0 = r"^(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+wtap_reg_regex1 = r"void\s+(?P<symbol>wtap_register_[_A-Za-z0-9]+)\s*\([^;]+$"
+
+# This table drives the pattern-matching and symbol-harvesting
+patterns = [
+ ( 'proto_reg', re.compile(proto_regex0) ),
+ ( 'proto_reg', re.compile(proto_regex1) ),
+ ( 'handoff_reg', re.compile(handoff_regex0) ),
+ ( 'handoff_reg', re.compile(handoff_regex1) ),
+ ( 'wtap_register', re.compile(wtap_reg_regex0) ),
+ ( 'wtap_register', re.compile(wtap_reg_regex1) ),
+ ]
+
+# Open our registration symbol cache
+cache = None
+if cache_filename:
+ try:
+ cache_file = open(cache_filename, 'rb')
+ cache = pickle.load(cache_file)
+ cache_file.close()
+ if not cache.has_key(VERSION_KEY) or cache[VERSION_KEY] != CUR_VERSION:
+ cache = {VERSION_KEY: CUR_VERSION}
+ except:
+ cache = {VERSION_KEY: CUR_VERSION}
+
+# Grep
+for filename in filenames:
+ file = open(filename)
+ cur_mtime = os.fstat(file.fileno())[ST_MTIME]
+ if cache and cache.has_key(filename):
+ cdict = cache[filename]
+ if cur_mtime == cdict['mtime']:
+# print "Pulling %s from cache" % (filename)
+ regs['proto_reg'].extend(cdict['proto_reg'])
+ regs['handoff_reg'].extend(cdict['handoff_reg'])
+ regs['wtap_register'].extend(cdict['wtap_register'])
+ file.close()
+ continue
+ # We don't have a cache entry
+ if cache is not None:
+ cache[filename] = {
+ 'mtime': cur_mtime,
+ 'proto_reg': [],
+ 'handoff_reg': [],
+ 'wtap_register': [],
+ }
+# print "Searching %s" % (filename)
+ for line in file.readlines():
+ for action in patterns:
+ regex = action[1]
+ match = regex.search(line)
+ if match:
+ symbol = match.group("symbol")
+ sym_type = action[0]
+ regs[sym_type].append(symbol)
+ if cache is not None:
+# print "Caching %s for %s: %s" % (sym_type, filename, symbol)
+ cache[filename][sym_type].append(symbol)
+ file.close()
+
+if cache is not None and cache_filename is not None:
+ cache_file = open(cache_filename, 'wb')
+ pickle.dump(cache, cache_file)
+ cache_file.close()
+
+# Make sure we actually processed something
+if len(regs['proto_reg']) < 1:
+ print "No protocol registrations found"
+ sys.exit(1)
+
+# Sort the lists to make them pretty
+regs['proto_reg'].sort()
+regs['handoff_reg'].sort()
+regs['wtap_register'].sort()
+
+reg_code = open(tmp_filename, "w")
+
+reg_code.write(preamble)
+
+# Make the routine to register all protocols
+if registertype == "plugin" or registertype == "plugin_wtap":
+ reg_code.write("""
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <gmodule.h>
+
+#include "moduleinfo.h"
+
+#ifndef ENABLE_STATIC
+G_MODULE_EXPORT const gchar version[] = VERSION;
+
+/* Start the functions we need for the plugin stuff */
+
+G_MODULE_EXPORT void
+plugin_register (void)
+{
+""");
+else:
+ reg_code.write("""
+#include "register.h"
+void
+register_all_protocols(register_cb cb, gpointer client_data)
+{
+""");
+
+for symbol in regs['proto_reg']:
+ if registertype == "plugin" or registertype == "plugin_wtap":
+ line = " {extern void %s (void); %s ();}\n" % (symbol, symbol)
+ else:
+ line = " {extern void %s (void); if(cb) (*cb)(RA_REGISTER, \"%s\", client_data); %s ();}\n" % (symbol, symbol, symbol)
+ reg_code.write(line)
+
+reg_code.write("}\n")
+
+
+# Make the routine to register all protocol handoffs
+if registertype == "plugin" or registertype == "plugin_wtap":
+ reg_code.write("""
+G_MODULE_EXPORT void
+plugin_reg_handoff(void)
+{
+""");
+else:
+ reg_code.write("""
+void
+register_all_protocol_handoffs(register_cb cb, gpointer client_data)
+{
+""");
+
+for symbol in regs['handoff_reg']:
+ if registertype == "plugin" or registertype == "plugin_wtap":
+ line = " {extern void %s (void); %s ();}\n" % (symbol, symbol)
+ else:
+ line = " {extern void %s (void); if(cb) (*cb)(RA_HANDOFF, \"%s\", client_data); %s ();}\n" % (symbol, symbol, symbol)
+ reg_code.write(line)
+
+reg_code.write("}\n")
+
+if registertype == "plugin":
+ reg_code.write("#endif\n");
+elif registertype == "plugin_wtap":
+ reg_code.write("""
+G_MODULE_EXPORT void
+register_wtap_module(void)
+{
+""");
+
+ for symbol in regs['wtap_register']:
+ line = " {extern void %s (void); %s ();}\n" % (symbol, symbol)
+ reg_code.write(line)
+
+ reg_code.write("}\n");
+ reg_code.write("#endif\n");
+else:
+ reg_code.write("""
+static gulong proto_reg_count(void)
+{
+""");
+
+ line = " return %d;\n" % len(regs['proto_reg'])
+ reg_code.write(line)
+
+ reg_code.write("""
+}
+""");
+ reg_code.write("""
+static gulong handoff_reg_count(void)
+{
+""");
+
+ line = " return %d;\n" % len(regs['handoff_reg'])
+ reg_code.write(line)
+
+ reg_code.write("""
+}
+""");
+ reg_code.write("""
+gulong register_count(void)
+{
+""");
+
+ line = " return proto_reg_count() + handoff_reg_count();"
+ reg_code.write(line)
+
+ reg_code.write("""
+}\n
+""");
+
+
+# Close the file
+reg_code.close()
+
+# Remove the old final_file if it exists.
+try:
+ os.stat(final_filename)
+ os.remove(final_filename)
+except OSError:
+ pass
+
+# Move from tmp file to final file
+os.rename(tmp_filename, final_filename)
+
+
diff --git a/tools/chdr-dissector/moduleinfo.h b/tools/chdr-dissector/moduleinfo.h
new file mode 100644
index 000000000..d8f0570c7
--- /dev/null
+++ b/tools/chdr-dissector/moduleinfo.h
@@ -0,0 +1,9 @@
+#ifdef PACKAGE
+#undef PACKAGE
+#endif
+#define PACKAGE "chdr"
+#ifdef VERSION
+#undef VERSION
+#endif
+#define VERSION "0.0.0.1"
+
diff --git a/tools/chdr-dissector/packet-chdr.c b/tools/chdr-dissector/packet-chdr.c
new file mode 100644
index 000000000..0c2748c6c
--- /dev/null
+++ b/tools/chdr-dissector/packet-chdr.c
@@ -0,0 +1,327 @@
+/* packet-chdr.c
+ * Dissector for UHD CHDR packets
+ *
+ *
+ * Copyright 2010-2013 Ettus Research LLC
+ *
+ * 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/>.
+ *
+ */
+
+#define CHDR_PORT 49153
+
+#include "config.h"
+
+#include <glib.h>
+#include <epan/packet.h>
+#include <ctype.h>
+#include <stdio.h>
+
+void proto_register_chdr(void);
+void proto_reg_handoff_chdr(void);
+
+static int proto_chdr = -1;
+static int hf_chdr = -1;
+static int hf_chdr_hdr = -1;
+static int hf_chdr_is_extension = -1;
+static int hf_chdr_reserved = -1;
+static int hf_chdr_has_time = -1;
+static int hf_chdr_eob = -1;
+static int hf_chdr_sequence = -1;
+static int hf_chdr_packet_size = -1;
+static int hf_chdr_stream_id = -1;
+static int hf_chdr_src_dev = -1;
+static int hf_chdr_src_ep = -1;
+static int hf_chdr_dst_dev = -1;
+static int hf_chdr_dst_ep = -1;
+static int hf_chdr_timestamp = -1;
+static int hf_chdr_payload = -1;
+
+/* the heuristic dissector is called on every packet with payload.
+ * The warning printed for this should only be printed once.
+ */
+static int heur_warning_printed = 0;
+
+/* Forward-declare the dissector functions */
+static void dissect_chdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
+
+/* Subtree handles: set by register_subtree_array */
+static gint ett_chdr = -1;
+static gint ett_chdr_id = -1;
+
+
+/* heuristic dissector call. Will always return. */
+static gboolean heur_dissect_chdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+ if(heur_warning_printed < 1){
+ printf("heuristic dissector for UHD CHDR always returns true!\n");
+ heur_warning_printed++;
+ }
+ dissect_chdr(tvb, pinfo, tree);
+ return (TRUE);
+}
+
+static void byte_swap(guint8 *bytes, gint len)
+{
+ guint8 tmp[4];
+
+ if(len != 4){
+ printf("FATAL! number of bytes don't match 32 bit!\n");
+ return;
+ }
+
+ memcpy(tmp, bytes, 4);
+ bytes[0] = tmp[3];
+ bytes[1] = tmp[2];
+ bytes[2] = tmp[1];
+ bytes[3] = tmp[0];
+}
+
+static guint64 get_timestamp(guint8 *bytes, gint len)
+{
+ guint64 ts;
+ guint64 trans;
+ int it;
+
+ if(len != 8){
+ printf("FATAL! timestamps always consist of 64 bits!\n");
+ }
+
+ byte_swap(bytes, 4);
+ byte_swap(bytes+4, 4);
+
+ ts = 0;
+ for(it = 0 ; it < 8 ; it++){
+ ts = ts << 8;
+ trans = (guint64) bytes[it];
+ ts = ts | trans;
+ }
+
+ return (ts);
+}
+
+/* The dissector itself */
+static void dissect_chdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+ // Here are all the variables
+ proto_item *item;
+ proto_item *stream_item;
+ proto_tree *chdr_tree;
+ proto_tree *stream_tree;
+ gint len;
+
+ gint flag_offset;
+ guint8 *bytes;
+ gboolean flag_has_time;
+ guint64 timestamp;
+ gboolean is_network;
+ gint endianness;
+ gint id_pos_usb[4] = {7, 6, 5, 4};
+ gint id_pos_net[4] = {4, 5, 6, 7};
+ gint id_pos[4] = {7, 6, 5, 4};
+
+ if(pinfo->match_uint == CHDR_PORT){
+ is_network = TRUE;
+ flag_offset = 0;
+ endianness = ENC_BIG_ENDIAN;
+ memcpy(id_pos, id_pos_net, 4 * sizeof(gint));
+ }
+ else{
+ is_network = FALSE;
+ flag_offset = 3;
+ endianness = ENC_LITTLE_ENDIAN;
+ memcpy(id_pos, id_pos_usb, 4 * sizeof(gint));
+ }
+
+ len = tvb_reported_length(tvb);
+
+ col_append_str(pinfo->cinfo, COL_PROTOCOL, "/CHDR");
+ col_append_sep_fstr(pinfo->cinfo, COL_INFO, NULL, "CHDR",
+ tvb_format_text_wsp(tvb, 0, len));
+
+ if (tree) {
+ /* Start with a top-level item to add everything else to */
+ item = proto_tree_add_item(tree, proto_chdr, tvb, 0, 16, ENC_NA);
+ chdr_tree = proto_item_add_subtree(item, ett_chdr);
+
+ bytes = tvb_get_string(tvb, 0, 4);
+ flag_has_time = bytes[flag_offset] & 0x20;
+
+ /* These lines add flag info to tree */
+ proto_tree_add_item(chdr_tree, hf_chdr_is_extension, tvb, flag_offset, 1, ENC_NA);
+ proto_tree_add_item(chdr_tree, hf_chdr_reserved, tvb, flag_offset, 1, ENC_NA);
+ proto_tree_add_item(chdr_tree, hf_chdr_has_time, tvb, flag_offset, 1, ENC_NA);
+ proto_tree_add_item(chdr_tree, hf_chdr_eob, tvb, flag_offset, 1, ENC_NA);
+
+ /* These lines add sequence, packet_size and stream ID */
+ proto_tree_add_item(chdr_tree, hf_chdr_sequence, tvb, is_network ? 0:2, 2, endianness);
+ proto_tree_add_item(chdr_tree, hf_chdr_packet_size, tvb, is_network ? 2:0, 2, endianness);
+
+ /* stream id can be broken down to 4 sections. these are collapsed in a subtree */
+ stream_item = proto_tree_add_item(chdr_tree, hf_chdr_stream_id, tvb, 4, 4, endianness);
+ stream_tree = proto_item_add_subtree(stream_item, ett_chdr_id);
+ proto_tree_add_item(stream_tree, hf_chdr_src_dev, tvb, id_pos[0], 1, ENC_NA);
+ proto_tree_add_item(stream_tree, hf_chdr_src_ep, tvb, id_pos[1], 1, ENC_NA);
+ proto_tree_add_item(stream_tree, hf_chdr_dst_dev, tvb, id_pos[2], 1, ENC_NA);
+ proto_tree_add_item(stream_tree, hf_chdr_dst_ep, tvb, id_pos[3], 1, ENC_NA);
+
+ /* if has_time flag is present interpret timestamp */
+ if(flag_has_time){
+ item = proto_tree_add_item(chdr_tree, hf_chdr_timestamp, tvb, 8, 8, endianness);
+
+ if(!is_network){
+ bytes = (guint8*) tvb_get_string(tvb, 8, 8);
+ timestamp = get_timestamp(bytes, 8);
+ }
+ }
+ }
+}
+
+void
+proto_register_chdr(void)
+{
+ static hf_register_info hf[] = {
+ { &hf_chdr,
+ { "CHDR", "chdr.hdr", FT_STRING, BASE_NONE,
+ NULL, 0x0, NULL, HFILL }
+ },
+ { &hf_chdr_is_extension,
+ { "CHDR is extension", "chdr.is_extension",
+ FT_BOOLEAN, BASE_NONE,
+ NULL, 0x80,
+ NULL, HFILL }
+ },
+ { &hf_chdr_reserved,
+ { "CHDR reserved", "chdr.reserved",
+ FT_BOOLEAN, BASE_NONE,
+ NULL, 0x40,
+ NULL, HFILL }
+ },
+ { &hf_chdr_has_time,
+ { "CHDR has time", "chdr.has_time",
+ FT_BOOLEAN, BASE_NONE,
+ NULL, 0x20,
+ NULL, HFILL }
+ },
+ { &hf_chdr_eob,
+ { "CHDR end of burst", "chdr.eob",
+ FT_BOOLEAN, BASE_NONE,
+ NULL, 0x10,
+ NULL, HFILL }
+ },
+ { &hf_chdr_sequence,
+ { "CHDR sequence", "chdr.sequence",
+ FT_UINT16, BASE_DEC,
+ NULL, 0x0FFF,
+ NULL, HFILL }
+ },
+ { &hf_chdr_packet_size,
+ { "CHDR packet size", "chdr.packet_size",
+ FT_UINT16, BASE_DEC,
+ NULL, 0x0,
+ NULL, HFILL }
+ },
+ { &hf_chdr_stream_id,
+ { "CHDR stream id", //name
+ "chdr.stream_id", //abbr
+ FT_IPv4, //type
+ BASE_NONE, //display
+ NULL, //strings
+ 0x0, //bitmask
+ NULL, //brief description
+ HFILL // id
+ }
+ },
+ { &hf_chdr_src_dev,
+ { "CHDR source device", //name
+ "chdr.src_dev", //abbr
+ FT_UINT8, //type
+ BASE_DEC, //display
+ NULL, //strings
+ 0x0, //bitmask
+ NULL, //brief description
+ HFILL // id
+ }
+ },
+ { &hf_chdr_src_ep,
+ { "CHDR source endpoint", //name
+ "chdr.src_ep", //abbr
+ FT_UINT8, //type
+ BASE_DEC, //display
+ NULL, //strings
+ 0x0, //bitmask
+ NULL, //brief description
+ HFILL // id
+ }
+ },
+ { &hf_chdr_dst_dev,
+ { "CHDR destination device", //name
+ "chdr.dst_dev", //abbr
+ FT_UINT8, //type
+ BASE_DEC, //display
+ NULL, //strings
+ 0x0, //bitmask
+ NULL, //brief description
+ HFILL // id
+ }
+ },
+ { &hf_chdr_dst_ep,
+ { "CHDR destination endpoint", //name
+ "chdr.dst_ep", //abbr
+ FT_UINT8, //type
+ BASE_DEC, //display
+ NULL, //strings
+ 0x0, //bitmask
+ NULL, //brief description
+ HFILL // id
+ }
+ },
+
+ { &hf_chdr_timestamp,
+ { "CHDR timestamp", //name
+ "chdr.timestamp", //abbr
+ FT_UINT64, //type
+ BASE_DEC, //display
+ NULL, //strings
+ 0x0, //bitmask
+ NULL, //brief description
+ HFILL
+ }
+ },
+ };
+
+ static gint *ett[] = {
+ &ett_chdr,
+ &ett_chdr_id
+ };
+
+ proto_chdr = proto_register_protocol("UHD CHDR", "CHDR", "chdr");
+ proto_register_field_array(proto_chdr, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+ register_dissector("chdr", dissect_chdr, proto_chdr);
+}
+
+/* Handler registration */
+void
+proto_reg_handoff_chdr(void)
+{
+ /* register heuristic dissector for use with USB */
+ heur_dissector_add("usb.bulk", heur_dissect_chdr, proto_chdr);
+
+ /* register dissector for UDP packets */
+ static dissector_handle_t chdr_handle;
+ chdr_handle = create_dissector_handle(dissect_chdr, proto_chdr);
+ dissector_add_uint("udp.port", CHDR_PORT, chdr_handle);
+}
+
diff --git a/tools/chdr-dissector/plugin.rc.in b/tools/chdr-dissector/plugin.rc.in
new file mode 100644
index 000000000..f9d714704
--- /dev/null
+++ b/tools/chdr-dissector/plugin.rc.in
@@ -0,0 +1,34 @@
+#include "winver.h"
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION @RC_MODULE_VERSION@
+ PRODUCTVERSION @RC_VERSION@
+ FILEFLAGSMASK 0x0L
+#ifdef _DEBUG
+ FILEFLAGS VS_FF_DEBUG
+#else
+ FILEFLAGS 0
+#endif
+ FILEOS VOS_NT_WINDOWS32
+ FILETYPE VFT_DLL
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "CompanyName", "Ettus Research LLC\0"
+ VALUE "FileDescription", "@PACKAGE@ dissector\0"
+ VALUE "FileVersion", "@MODULE_VERSION@\0"
+ VALUE "InternalName", "@PACKAGE@ @MODULE_VERSION@\0"
+ VALUE "LegalCopyright", "Copyright © 2013 Ettus Research LLC\0"
+ VALUE "OriginalFilename", "@PLUGIN_NAME@.dll\0"
+ VALUE "ProductName", "Wireshark\0"
+ VALUE "ProductVersion", "@VERSION@\0"
+ VALUE "Comments", "Build with @MSVC_VARIANT@\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
diff --git a/tools/uhd_dump/Makefile b/tools/uhd_dump/Makefile
new file mode 100644
index 000000000..93181570b
--- /dev/null
+++ b/tools/uhd_dump/Makefile
@@ -0,0 +1,23 @@
+INCLUDES = usrp3_regs.h uhd_dump.h
+
+BINARIES = chdr_log
+
+OBJECTS = uhd_dump.o
+
+CFLAGS = -g -O0 -Wall
+
+LDFLAGS = -lpcap -lm
+
+CC = cc
+
+.PHONY: all
+all: $(BINARIES)
+
+chdr_log: uhd_dump.o chdr_log.o $(INCLUDES)
+ $(CC) $(CFLAGS) -o $@ uhd_dump.o chdr_log.o $(LDFLAGS)
+
+
+
+clean:
+ rm $(BINARIES) $(BINARIES:%=%.o) $(OBJECTS)
+
diff --git a/tools/uhd_dump/chdr_log.c b/tools/uhd_dump/chdr_log.c
new file mode 100644
index 000000000..9a0834e9b
--- /dev/null
+++ b/tools/uhd_dump/chdr_log.c
@@ -0,0 +1,212 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <pcap.h>
+#include <netinet/in.h>
+#include <time.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "uhd_dump.h"
+
+//#define DEBUG 1
+
+void usage()
+{
+ fprintf(stderr,"Usage: chdr_dump [-h host_ip] filename.pcap\n");
+ exit(2);
+}
+
+int main(int argc, char *argv[])
+{
+ struct pbuf_info *packet_buffer; // Store all packets of interest here
+ struct in_addr host_addr; // Apparent Host IP addr in this capture
+ struct in_addr usrp_addr; // Apparent USRP IP addr in this capture
+ struct timeval *origin_ts; // Timestamp of first packet in file.
+ long long origin_ts_in_us;
+ int direction; // Flag to show direction of packet flow. 0=H->U, 1=U->H.
+ int packet_count[2]; // Number of packets that match filter
+ double size_average[2]; // Average size of packets Host to USRP
+ int size_histogram[90][2]; // Array captures histogram of packet sizes Host to USRP in 100 byte bins
+ int x; // Local integer scratch variables
+ char *conversion_error[1];
+ int c;
+ char buffer[26]; // Buffer to format GMT time stamp strings for output
+ double time_since_start; // Time elapsed in seconds since start
+
+ const struct ip_header *ip_header;
+
+ u32 *dump_header;
+
+
+ host_addr.s_addr = 0x0;
+ //usrp_addr.s_addr = 0x0;
+
+ while ((c = getopt(argc, argv, "h:u:")) != -1) {
+ switch(c) {
+ case 'h':
+ // Explicit IP address for host on command line
+ if (*optarg == '\0')
+ usage();
+ host_addr.s_addr = strtol(strtok(optarg,"."),conversion_error,10) ;
+ if (**conversion_error != '\0')
+ usage();
+ host_addr.s_addr = host_addr.s_addr | strtol(strtok(NULL,"."),conversion_error,10) << 8;
+ if (**conversion_error != '\0')
+ usage();
+ host_addr.s_addr = host_addr.s_addr | strtol(strtok(NULL,"."),conversion_error,10) << 16;
+ if (**conversion_error != '\0')
+ usage();
+ host_addr.s_addr = host_addr.s_addr | strtol(strtok(NULL,"\0"),conversion_error,10) << 24;
+ if (**conversion_error != '\0')
+ usage();
+ break;
+ case 'u':
+ // Explicit IP address for USRP on command line
+ if (*optarg == '\0')
+ usage();
+ usrp_addr.s_addr = strtol(strtok(optarg,"."),conversion_error,10) ;
+ if (**conversion_error != '\0')
+ usage();
+ usrp_addr.s_addr = usrp_addr.s_addr | strtol(strtok(NULL,"."),conversion_error,10) << 8;
+ if (**conversion_error != '\0')
+ usage();
+ usrp_addr.s_addr = usrp_addr.s_addr | strtol(strtok(NULL,"."),conversion_error,10) << 16;
+ if (**conversion_error != '\0')
+ usage();
+ usrp_addr.s_addr = usrp_addr.s_addr | strtol(strtok(NULL,"\0"),conversion_error,10) << 24;
+ if (**conversion_error != '\0')
+ usage();
+ break;
+
+ case'?':
+ default:
+ usage();
+ }
+ }
+
+ argc -= (optind - 1);
+ argv += (optind -1);
+
+
+ // Just a mandatory pcap filename for now, better parser and options later.
+ if (argc != 2) {
+ usage();
+ }
+
+
+ // Init packet buffer
+ packet_buffer = malloc(sizeof(struct pbuf_info));
+
+ // Init origin timestamp
+ origin_ts = malloc(sizeof(struct timeval));
+
+ // Go read matching packets from capture file into memory
+ get_udp_port_from_file(CHDR_PORT,argv[1],packet_buffer,origin_ts);
+
+ // Extract origin tome of first packet and convert to uS.
+ origin_ts_in_us = origin_ts->tv_sec * 1000000 + origin_ts->tv_usec;
+
+
+ // Count number of packets in capture
+ packet_buffer->current = packet_buffer->start;
+ x = 0;
+
+ while (packet_buffer->current != NULL) {
+ x++;
+ packet_buffer->current = packet_buffer->current->next;
+ }
+
+ fprintf(stdout,"\n===================================================================\n");
+ fprintf(stdout,"\n Total matching packet count in capture file: %d\n",x);
+ fprintf(stdout,"\n===================================================================\n\n");
+
+ // If no packets were CHDR then just exit now
+ if (x == 0) {
+ exit(0);
+ }
+
+ // Determine host and USRP IP addresses so that we can classify direction of packet flow later.
+ if (host_addr.s_addr == 0x0)
+ get_connection_endpoints(packet_buffer,&host_addr,&usrp_addr);
+
+ // Count packets in list.
+ // Build histogram of packet sizes
+ // Build histogram of Stream ID's
+ packet_buffer->current = packet_buffer->start;
+
+ for (x=0;x<90;x+=1)
+ size_histogram[x][H2U] = size_histogram[x][U2H] = 0;
+
+ size_average[H2U] = size_average[U2H] = 0;
+ packet_count[H2U] = packet_count[U2H] = 0;
+
+ while (packet_buffer->current != NULL) {
+
+ // Overlay IP header on packet payload
+ ip_header = (struct ip_header *)(packet_buffer->current->payload+ETH_SIZE);
+
+ // Identify packet direction
+ if (ip_header->ip_src.s_addr == host_addr.s_addr)
+ direction = H2U;
+ else
+ direction = U2H;
+
+ packet_count[direction]++;
+ size_average[direction]+=(double)packet_buffer->current->size;
+ if ((x=packet_buffer->current->size) > 9000)
+ fprintf(stderr,"Current packet size = %d at absolute time %s, relative time %f, exceeds MTU! Skip counting.",
+ x,format_gmt(&packet_buffer->current->ts,buffer),(relative_time(&packet_buffer->current->ts,origin_ts)));
+ else
+ size_histogram[x/100][direction]++;
+
+ packet_buffer->current = packet_buffer->current->next;
+
+ }
+
+ fprintf(stdout,"\n===================================================================\n");
+ fprintf(stdout,"\n Average packet size Host -> USRP: %d\n",(int)(size_average[H2U]/packet_count[H2U]));
+ fprintf(stdout,"\n Average packet size USRP -> Host: %d\n",(int)(size_average[U2H]/packet_count[U2H]));
+ fprintf(stdout,"\n===================================================================\n\n");
+
+ //
+ // Now produce packet by packet log
+ //
+ packet_buffer->current = packet_buffer->start;
+ x = 0;
+
+ while (packet_buffer->current != NULL) {
+ x++;
+
+ // Calculate time offset of this packet from start
+ time_since_start = ((double) packet_buffer->current->ts.tv_sec * 1000000 + packet_buffer->current->ts.tv_usec - origin_ts_in_us)/1000000;
+
+
+ dump_header = (u32 *) (packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE);
+
+ /* fprintf(stdout,"DUMP: %08x %08x %08x %08x %08x %08x\n", */
+ /* swapint((int) *(dump_header)), */
+ /* swapint((int) *(dump_header+1)), */
+ /* swapint((int) *(dump_header+2)), */
+ /* swapint((int) *(dump_header+3)), */
+ /* swapint((int) *(dump_header+4)), */
+ /* swapint((int) *(dump_header+5))); */
+
+ // Extract the device portion of the SID to see which packet flow this belongs in
+
+ fprintf(stdout,"%8d %f \t",x,time_since_start);
+ print_direction(packet_buffer,&host_addr,&usrp_addr);
+ fprintf(stdout,"\t");
+ print_size(packet_buffer);
+ fprintf(stdout,"\t");
+ print_sid(packet_buffer);
+ fprintf(stdout,"\t");
+ print_vita_header(packet_buffer,&host_addr);
+ fprintf(stdout,"\n");
+
+ packet_buffer->current = packet_buffer->current->next;
+
+ }
+ // Normal Exit
+ return(0);
+}
+
diff --git a/tools/uhd_dump/uhd_dump.c b/tools/uhd_dump/uhd_dump.c
new file mode 100644
index 000000000..3238d72cf
--- /dev/null
+++ b/tools/uhd_dump/uhd_dump.c
@@ -0,0 +1,531 @@
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pcap.h>
+#include <netinet/in.h>
+#include <time.h>
+#include <string.h>
+
+#include "uhd_dump.h"
+#include "usrp3_regs.h"
+
+
+// Swap endianness of 64bits
+unsigned long swaplong (unsigned long nLongNumber)
+{
+ union u {unsigned long vi; unsigned char c[sizeof(unsigned long)];};
+ union v {unsigned long ni; unsigned char d[sizeof(unsigned long)];};
+ union u un;
+ union v vn;
+ un.vi = nLongNumber;
+ vn.d[0]=un.c[7];
+ vn.d[1]=un.c[6];
+ vn.d[2]=un.c[5];
+ vn.d[3]=un.c[4];
+ vn.d[4]=un.c[3];
+ vn.d[5]=un.c[2];
+ vn.d[6]=un.c[1];
+ vn.d[7]=un.c[0];
+
+ return (vn.ni);
+}
+
+// Swap endianness of 32bits
+unsigned int swapint (unsigned int nIntNumber)
+{
+ union u {unsigned int vi; unsigned char c[sizeof(unsigned long)];};
+ union v {unsigned int ni; unsigned char d[sizeof(unsigned long)];};
+ union u un;
+ union v vn;
+ un.vi = nIntNumber;
+ vn.d[0]=un.c[3];
+ vn.d[1]=un.c[2];
+ vn.d[2]=un.c[1];
+ vn.d[3]=un.c[0];
+ return (vn.ni);
+}
+
+// Swap Endianness of 16bits
+unsigned short swapshort (unsigned short nShortNumber)
+{
+ union u {unsigned short vi; unsigned char c[sizeof(unsigned short)];};
+ union v {unsigned short ni; unsigned char d[sizeof(unsigned short)];};
+ union u un;
+ union v vn;
+ un.vi = nShortNumber;
+ vn.d[0]=un.c[1];
+ vn.d[1]=un.c[0];
+
+ return (vn.ni);
+}
+
+// Format time from pcap as ascii style.
+char *format_gmt(const struct timeval *ts, char *buffer)
+{
+ time_t seconds;
+ struct tm gmt;
+ seconds = ts->tv_sec;
+ if ((gmtime_r(&seconds, &gmt)) == NULL) {
+ fprintf(stderr, "Fatal time format conversion error.\n");
+ exit(2);
+ }
+ sprintf(buffer,
+ "%04i-%02i-%02iT%02i:%02i:%02i,%03iZ",
+ gmt.tm_year + 1900, gmt.tm_mon + 1, gmt.tm_mday,
+ gmt.tm_hour, gmt.tm_min, gmt.tm_sec, (int) (ts->tv_usec / 1000));
+ return (buffer);
+}
+
+// Takes 2 timeval absolute timevalues, and returns a double value thats the relative time
+// difference normalized to seconds.
+double relative_time(struct timeval *event_ts, struct timeval *origin_ts)
+{
+ struct timeval z;
+ double x;
+ timersub(event_ts,origin_ts,&z);
+ x = (double)z.tv_sec + (double)z.tv_usec/1000000;
+ return x;
+}
+
+// Convert timeval to double, normalized to seconds.
+double timeval2double(struct timeval *event_ts)
+{
+ double x;
+ x = (double)event_ts->tv_sec + (double)event_ts->tv_usec/1000000;
+ return x;
+}
+
+void get_packet(struct pbuf_info *packet_buffer , const struct pcap_pkthdr *header, const u_char *packet)
+{
+ // Get size of new packet
+ packet_buffer->current->size = header->caplen;
+ packet_buffer->current->orig_size = header->len;
+
+ // Allocate memory for packet
+ packet_buffer->current->payload = (char *)malloc((size_t)packet_buffer->current->size);
+
+ // Copy Packet into buffer
+ memcpy(packet_buffer->current->payload,packet,packet_buffer->current->size);
+ packet_buffer->current->ts = header->ts;
+
+ // Allocate memory for next pbuf in chain, init it and shift list.
+ packet_buffer->current->next = malloc(sizeof (struct pbuf));
+ packet_buffer->current->next->last = packet_buffer->current;
+ packet_buffer->current = packet_buffer->current->next;
+}
+
+// This grabs the (absolute) time stamp of the first packet in the cature file, which can be used to
+// derive times relative to the start of the capture file for cross correlation with interactive work
+// in Wireshark
+void get_start_time(struct timeval *ts , const struct pcap_pkthdr *header, const u_char *packet)
+{
+ *ts = header->ts;
+}
+
+void get_udp_port_from_file(const u16 udp_port, const char *filename, struct pbuf_info *packet_buffer, struct timeval *ts)
+{
+ pcap_t *handle; // Session handle
+ char errbuf[PCAP_ERRBUF_SIZE]; // Error string
+ char filter_exp[256]; // The ascii filter expression
+ struct bpf_program filter; // The compiled filter
+
+ // Open PCAP file for read capture time stamp of first packet
+ if ((handle = pcap_open_offline(filename,errbuf)) == NULL) {
+ fprintf(stderr,"Can't open pcap file for reading: %s\n",errbuf);
+ exit(2);
+ }
+
+ // Parse PCAP file with no filter to grab the time stamp of the first captured packet, which becomes the time origin
+ // local to the capture file.
+ if (pcap_dispatch(handle, 1, (pcap_handler) get_start_time, (u_char *)ts) == -1) {
+ fprintf(stderr, "Error parsing PCAP file: %s\n", pcap_geterr(handle));
+ exit(2);
+ }
+
+ // Close file again because no way to rewind file descriptor.
+ pcap_close(handle);
+
+ // Open PCAP file for read.
+ if ((handle = pcap_open_offline(filename,errbuf)) == NULL) {
+ fprintf(stderr,"Can't open pcap file for reading: %s\n",errbuf);
+ exit(2);
+ }
+
+ // Build ASCII filter expression from UDP port
+ sprintf(filter_exp,"udp port %d",udp_port);
+ printf("\nBPF filter is udp port %d\n",udp_port);
+
+ // Compile filter string to BPF
+ if (pcap_compile(handle, &filter, filter_exp, 0, 0) == -1) {
+ fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle));
+ exit(2);
+ }
+
+ // Apply filter
+ if (pcap_setfilter(handle, &filter) == -1) {
+ fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle));
+ exit(2);
+ }
+
+ // Allocate and initialize packet buffer linked list
+ packet_buffer->start = packet_buffer->current = malloc(sizeof (struct pbuf));
+ packet_buffer->start->last = NULL;
+
+ // Parse PCAP file using filter, collect all interesting packets.
+ if (pcap_dispatch(handle, -1, (pcap_handler) get_packet, (u_char *)packet_buffer) == -1) {
+ fprintf(stderr, "Error parsing PCAP file: %s\n", pcap_geterr(handle));
+ exit(2);
+ }
+
+ // If no packets matched in the capture then linked list should be completely empty.
+ if ( packet_buffer->start == packet_buffer->current) {
+ free(packet_buffer->current);
+ packet_buffer->start = packet_buffer->current = NULL;
+ } else {
+ // Note the last used buffer in the list. Removed allocated but unused buffer from list and free
+ packet_buffer->end = packet_buffer->current->last;
+ packet_buffer->end->next = NULL;
+ free(packet_buffer->current);
+ }
+}
+
+//
+// Read a pcap file into memory.
+//
+void get_everything_from_file(const char *filename, struct pbuf_info *packet_buffer, struct timeval *ts)
+{
+ pcap_t *handle; // Session handle
+ char errbuf[PCAP_ERRBUF_SIZE]; // Error string
+
+ // Open PCAP file for read capture time stamp of first packet
+ if ((handle = pcap_open_offline(filename,errbuf)) == NULL) {
+ fprintf(stderr,"Can't open pcap file for reading: %s\n",errbuf);
+ exit(2);
+ }
+
+ // Parse PCAP file with no filter to grab the time stamp of the first captured packet, which becomes the time origin
+ // local to the capture file.
+ if (pcap_dispatch(handle, 1, (pcap_handler) get_start_time, (u_char *)ts) == -1) {
+ fprintf(stderr, "Error parsing PCAP file: %s\n", pcap_geterr(handle));
+ exit(2);
+ }
+
+ // Close file again because no way to rewind file descriptor.
+ pcap_close(handle);
+
+ // Open PCAP file for read
+ if ((handle = pcap_open_offline(filename,errbuf)) == NULL) {
+ fprintf(stderr,"Can't open pcap file for reading: %s\n",errbuf);
+ exit(2);
+ }
+
+ // Allocate and initialize packet buffer linked list
+ packet_buffer->start = packet_buffer->current = malloc(sizeof (struct pbuf));
+ packet_buffer->start->last = NULL;
+
+ // Parse PCAP file using filter, collect all interesting packets.
+ if (pcap_dispatch(handle, -1, (pcap_handler) get_packet, (u_char *)packet_buffer) == -1) {
+ fprintf(stderr, "Error parsing PCAP file: %s\n", pcap_geterr(handle));
+ exit(2);
+ }
+
+ // If no packets matched in the capture then linked list should be completely empty.
+ if ( packet_buffer->start == packet_buffer->current) {
+ free(packet_buffer->current);
+ packet_buffer->start = packet_buffer->current = NULL;
+ } else {
+ // Note the last used buffer in the list. Removed allocated but unused buffer from list and free
+ packet_buffer->end = packet_buffer->current->last;
+ packet_buffer->end->next = NULL;
+ free(packet_buffer->current);
+ }
+}
+
+
+// Debug
+void print_raw(const struct pbuf_info *packet_buffer, const int count)
+{
+ const u8 *raw;
+ int x;
+ raw = (u8 *) packet_buffer;
+ fprintf(stdout," ");
+ for (x = 0; x<count; x++)
+ fprintf(stdout,"%02x ",*(raw+x));
+}
+
+// Print to STDOUT the direction of this packet flow
+void print_direction(const struct pbuf_info *packet_buffer, const struct in_addr *host_addr, const struct in_addr *usrp_addr)
+{
+ const struct ip_header *ip_header;
+
+ // Overlay IP header on packet payload
+ ip_header = (struct ip_header *)(packet_buffer->current->payload+ETH_SIZE);
+
+ if ((host_addr->s_addr == ip_header->ip_src.s_addr) && (usrp_addr->s_addr == ip_header->ip_dst.s_addr))
+ fprintf(stdout,"Host->USRP");
+ else if ((host_addr->s_addr == ip_header->ip_dst.s_addr) && (usrp_addr->s_addr == ip_header->ip_src.s_addr))
+ fprintf(stdout,"USRP->Host");
+ else
+ fprintf(stdout,"UNKNOWN");
+}
+
+// Print to STDOUT the CHDR size in bytes
+void print_size(const struct pbuf_info *packet_buffer)
+{
+ const struct chdr_header *chdr_header;
+
+ // Overlay CHDR header on packet payload
+ chdr_header = (struct chdr_header *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE);
+
+ fprintf(stdout,"Size: %04d ",(swapint(chdr_header->chdr_type) & SIZE));
+}
+
+// Print to STDOUT the CHDR SID decode
+void print_sid(const struct pbuf_info *packet_buffer)
+{
+ const struct chdr_header *chdr_header;
+ const struct chdr_sid *chdr_sid;
+
+ // Overlay CHDR header on packet payload
+ chdr_header = (struct chdr_header *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE);
+
+ // Overlay CHDR SID definition on CHDR SID.
+ chdr_sid = (struct chdr_sid *)&(chdr_header->chdr_sid);
+
+ fprintf(stdout,"%02x.%02x->%02x.%02x",chdr_sid->src_device,chdr_sid->src_endpoint,chdr_sid->dst_device,chdr_sid->dst_endpoint);
+}
+
+// Print to STDOUT a decoded tx response packet payload.
+void print_tx_response(const struct tx_response *tx_response)
+{
+ switch(swapint(tx_response->error_code))
+ {
+ case TX_ACK: fprintf(stdout,"ACK "); break;
+ case TX_EOB: fprintf(stdout,"EOB "); break;
+ case TX_UNDERRUN: fprintf(stdout,"Underrun "); break;
+ case TX_SEQ_ERROR: fprintf(stdout,"Sequence Error "); break;
+ case TX_TIME_ERROR: fprintf(stdout,"Time Error "); break;
+ case TX_MIDBURST_SEQ_ERROR: fprintf(stdout,"Mid-Burst Seq Errror "); break;
+ default: fprintf(stdout,"Unknown Error ");
+ }
+ fprintf(stdout,"for SeqID = %03x ",swapint(tx_response->seq_id)&0xFFF);
+}
+
+
+
+// Returns Name of a register from it's address
+char *reg_addr_to_name(const u32 addr)
+{
+ int x;
+ x = 0;
+ while((reg_list[x].addr != addr) && (reg_list[x].addr != 999))
+ x++;
+ return(reg_list[x].name);
+}
+
+// Print to STDOUT decode of CHDR header including time if present.
+void print_vita_header(const struct pbuf_info *packet_buffer, const struct in_addr *host_addr)
+{
+ const struct ip_header *ip_header;
+ const struct chdr_header *chdr_header;
+ const struct chdr_sid *chdr_sid;
+ const struct radio_ctrl_payload *radio_ctrl_payload;
+ const struct radio_response *radio_response;
+ const struct tx_response *tx_response;
+ const struct src_flow_ctrl *src_flow_ctrl;
+ const struct vita_time *vita_time;
+ int direction;
+ u8 endpoint;
+ int has_time;
+
+ // Overlay IP header on packet payload
+ ip_header = (struct ip_header *)(packet_buffer->current->payload+ETH_SIZE);
+
+ // Overlay CHDR header on packet payload
+ chdr_header = (struct chdr_header *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE);
+
+ // Overlay CHDR SID definition on CHDR SID.
+ chdr_sid = (struct chdr_sid *)&(chdr_header->chdr_sid);
+
+ // Identify packet direction
+ if (ip_header->ip_src.s_addr == host_addr->s_addr)
+ direction = H2U;
+ else
+ direction = U2H;
+
+ // Decode packet type
+
+
+ if ((swapint(chdr_header->chdr_type) & EXT_CONTEXT) == EXT_CONTEXT) fprintf(stdout,"Context Ext ");
+ else fprintf(stdout,"IF Data ");
+
+ // Determine USRP Sink/Src Endpoint
+ if (direction==H2U)
+ endpoint = (chdr_sid->dst_endpoint) & 0x3;
+ else if (direction==U2H)
+ endpoint = (chdr_sid->src_endpoint) & 0x3;
+
+ // Look for CHDR EOB flags.
+ if ((swapint(chdr_header->chdr_type) & EOB) == EOB) fprintf(stdout,"EOB ");
+ else fprintf(stdout," ");
+
+ // Is there embeded VITA time?
+ if ((swapint(chdr_header->chdr_type) & HAS_TIME) == HAS_TIME) {
+ vita_time = (struct vita_time *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE+CHDR_SIZE);
+ fprintf(stdout,"Time=%016lx ",swaplong(vita_time->time));
+ has_time = 1;
+ } else {
+ fprintf(stdout," ");
+ has_time = 0;
+ }
+
+ fprintf(stdout,"SeqID=%03x ",(swapint(chdr_header->chdr_type)>>16)&0xFFF);
+
+ // Print Payload
+ if (endpoint == RADIO)
+ {
+ if ((swapint(chdr_header->chdr_type) & EXT_CONTEXT) != EXT_CONTEXT)
+ {
+ if (direction == H2U)
+ {
+ fprintf(stdout,"TX IF Data ");
+ }
+ else
+ // U2H
+ {
+ fprintf(stdout,"RX IF Data ");
+ }
+ }
+ else if ((swapint(chdr_header->chdr_type) & EXT_CONTEXT) == EXT_CONTEXT)
+ {
+ if (direction == H2U)
+ {
+ // BAD PACKET
+ }
+ else
+ // U2H
+ {
+ // TX Response packet.
+ tx_response = (struct tx_response *) (packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE+CHDR_SIZE+(has_time?VITA_TIME_SIZE:0));
+ print_tx_response(tx_response);
+ }
+ }
+ }
+ else if (endpoint == RADIO_CTRL)
+ {
+ fprintf(stdout,"\t\t\t");
+ if ((swapint(chdr_header->chdr_type) & EXT_CONTEXT) != EXT_CONTEXT)
+ {
+ // BAD PACKET
+ }
+ else if ((swapint(chdr_header->chdr_type) & EXT_CONTEXT) == EXT_CONTEXT)
+ {
+ if (direction == H2U)
+ {
+ radio_ctrl_payload = (struct radio_ctrl_payload *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE+CHDR_SIZE+(VITA_TIME_SIZE*has_time));
+ fprintf(stdout,"Radio Ctrl %s(0x%02x)=0x%08x",reg_addr_to_name(swapint(radio_ctrl_payload->addr)),(u8)swapint(radio_ctrl_payload->addr),swapint(radio_ctrl_payload->data));
+ }
+ else
+ // U2H
+ {
+ radio_response = (struct radio_response *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE+CHDR_SIZE+(VITA_TIME_SIZE*has_time));
+ fprintf(stdout,"Radio Response = 0x%016lx",swaplong(radio_response->data));
+ }
+ }
+ }
+ else if (endpoint == SRC_FLOW_CTRL)
+ {
+ if ((swapint(chdr_header->chdr_type) & EXT_CONTEXT) != EXT_CONTEXT)
+ {
+ // BAD PACKET
+ }
+ else if ((swapint(chdr_header->chdr_type) & EXT_CONTEXT) == EXT_CONTEXT)
+ {
+ if (direction == H2U)
+ {
+ src_flow_ctrl = (struct src_flow_ctrl *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE+CHDR_SIZE+(VITA_TIME_SIZE*has_time));
+ fprintf(stdout,"Src Flow Ctrl = 0x%04x",swapint(src_flow_ctrl->seq_id));
+ }
+ else
+ // U2H
+ {
+ // Bad Packet
+ }
+ }
+ }
+ //print_raw((struct pbuf_info *)vrt_header,16);
+}
+
+
+// Find IP addresses for Host and USRP in this Session
+
+void get_connection_endpoints( struct pbuf_info *packet_buffer, struct in_addr *host_addr, struct in_addr *usrp_addr)
+{
+ const struct ip_header *ip_header;
+ const struct chdr_header *chdr_header;
+ const struct chdr_sid *chdr_sid;
+
+ // Determine which side of the stream is Host and which is USRP by probing capture until a
+ // CHDR message type is discovered. The SID reveals which direction the packet is traveling.
+ // Then record apparent IP addresses of Host and USRP for future packet clasification.
+ packet_buffer->current = packet_buffer->start;
+
+ host_addr->s_addr = 0x0;
+ usrp_addr->s_addr = 0x0;
+
+ while (packet_buffer->current != NULL) {
+
+ // Overlay IP header on packet payload
+ ip_header = (struct ip_header *)(packet_buffer->current->payload+ETH_SIZE);
+
+ // Overlay CHDR header on packet payload
+ chdr_header = (struct chdr_header *)(packet_buffer->current->payload+ETH_SIZE+IP_SIZE+UDP_SIZE);
+
+ // Overlay CHDR SID definition on CHDR SID.
+ chdr_sid = (struct chdr_sid *)&(chdr_header->chdr_sid);
+
+
+ // Catagorise stream
+ // CHDR is actually quite hard to conclusively detect, the following deductions help...
+ // For CHDR v2 bit 62 should always be 0 (reserved)
+ // Bit 47 should always be 0 because sizes > 8192 are unsupport be typical ethernet MTU's
+ // By convention currently the host uses SID address 0.x so the first packets in a new UHD session
+ // should flow from Host to Device hence [31:24] = 0.
+ if (
+ ((swapint(chdr_header->chdr_type) & 0x40000000) != 0x0) ||
+ ((swapint(chdr_header->chdr_type) & 0x8000) != 0x0) ||
+ ((swapint(chdr_header->chdr_sid) & 0xFF000000) != 0x0) ||
+ ((swapint(chdr_header->chdr_sid) & 0x0000FF00) == 0x0)
+ )
+ fprintf(stderr,"Current packet is not CHDR. Skipping.");
+ else
+ {
+ // Implicitly CHDR (At least that is our best guess)
+ // Go take a look at the SID and see who is boss.
+ if ((chdr_sid->src_device == 0) && (chdr_sid->dst_device != 0))
+ {
+ // Host->USRP
+ host_addr->s_addr = ip_header->ip_src.s_addr;
+ usrp_addr->s_addr = ip_header->ip_dst.s_addr;
+ break;
+ }
+ else if ((chdr_sid->src_device == 0) && (chdr_sid->dst_device != 0))
+ {
+ // USRP->Host
+ usrp_addr->s_addr = ip_header->ip_src.s_addr;
+ host_addr->s_addr = ip_header->ip_dst.s_addr;
+ break;
+ }
+ else
+ {
+ fprintf(stderr,"Malformed CHDR packet, SID is unexpected value: 0x%x",swapint(chdr_header->chdr_sid));
+ }
+ }
+ packet_buffer->current = packet_buffer->current->next;
+ }
+
+ if (host_addr->s_addr == 0) {
+ fprintf(stderr, "Could not identify Host/USRP direction in capture analysis, exiting.\n");
+ exit(2);
+ }
+}
diff --git a/tools/uhd_dump/uhd_dump.h b/tools/uhd_dump/uhd_dump.h
new file mode 100644
index 000000000..2c36f9a39
--- /dev/null
+++ b/tools/uhd_dump/uhd_dump.h
@@ -0,0 +1,238 @@
+
+#ifndef _UHD_DUMP_H_
+#define _UHD_DUMP_H_
+
+
+
+#define FALSE 0
+#define TRUE 1
+#define UNKNOWN 2
+
+// Define directions for Host->USRP & USRP->Host
+#define H2U 0
+#define U2H 1
+
+// Endpoint encodings for USRP3 from SID LSB's
+#define RADIO 0
+#define RADIO_CTRL 1
+#define SRC_FLOW_CTRL 2
+#define RESERVED 3
+
+/* // VRT Type definitions */
+/* #define IF_DATA_NO_SID 0 */
+/* #define IF_DATA_WITH_SID 1 */
+/* #define EXT_DATA_NO_SID 2 */
+/* #define EXT_DATA_WITH_SID 3 */
+/* #define IF_CONTEXT 4 */
+/* #define EXT_CONTEXT 5 */
+
+// CHDR bit masks
+#define EXT_CONTEXT 1<<31
+#define HAS_TIME 1<<29
+#define EOB 1<<28
+#define SIZE (1<<16)-1
+
+
+// UDP used as source for all CHDR comms.
+#define CHDR_PORT 49153
+
+typedef unsigned char bool;
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int u32;
+typedef unsigned long u64;
+
+union ip_addr_decoder {
+ unsigned long s_addr;
+ unsigned char octet[4];
+};
+
+/*
+Ethernet header structure
+*/
+
+struct ethernet_header {
+ u8 eth_dst[6]; // MAC addr of destination
+ u8 eth_src[6]; // MAC addr of source
+ u16 eth_typ; // Payload protocol type
+};
+
+#define ETH_SIZE 14
+
+/*
+ IP Header strcture
+ NOTE: Network byte order (Big Endian)
+*/
+
+struct ip_header {
+ u8 ip_vhl; // [7:4] Version, [3:0] Header Length
+ u8 ip_tos; // Type of Service/DIff Serv/ECN
+ u16 ip_len; // Total Length
+ u16 ip_id; // Identification
+ u16 ip_off; // [15:14] Flags, [13:0] Fragment Offset
+ u8 ip_ttl; // Time To Live
+ u8 ip_pro; // Protocol
+ u16 ip_sum; // Checksum
+ struct in_addr ip_src; // IP Source address
+ struct in_addr ip_dst; // IP Destination address
+};
+
+#define IP_SIZE 20
+
+/*
+ UDP Header Structure
+ NOTE: Network byte order (Big Endian)
+*/
+
+struct udp_header {
+ u16 udp_src; // Source Port
+ u16 udp_dst; // Destination Port
+ u16 udp_len; // Length
+ u16 udp_sum; // Checksum
+};
+
+#define UDP_SIZE 8
+
+/* /\* */
+/* VITA49 VRLP Header */
+/* NOTE: Network byte order (Big Endian) */
+/* *\/ */
+
+/* struct vrlp_header { */
+/* u32 vrlp_start; // Hardcoded to ASCII "VRLP" */
+/* u32 vrlp_size; // [31:20] Frame Count, [19:0] Frame Size */
+/* }; */
+
+/* #define VRLP_SIZE 8 */
+
+/* #define VRLP_SEQID(x) (((x & 0xff)<<4) | ((x & 0xf000) >> 12)) */
+
+/* /\* */
+/* VITA49 VRLP Trailer */
+/* NOTE: Network byte order (Big Endian) */
+/* *\/ */
+
+/* struct vrlp_trailer { */
+/* u32 vrlp_end; // Hardcoded to ASCII "VEND" */
+/* }; */
+
+/* #define VRLP_TRAILER_SIZE 4 */
+
+/* /\* */
+/* VITA49 VRT Header */
+/* NOTE: Network byte order (Big Endian) */
+/* *\/ */
+
+/* struct vrt_header { */
+/* u8 vrt_type; // [7:4] type, [3] Class ID flag, [2] Trailer flag, [1] SOB, [0] EOB */
+/* u8 vrt_count; // [7:6] TSI, [5:4] TSF, [3:0] Packet Count modulo 16 */
+/* u16 vrt_size; // Number of 32bit words in VRT packet including headers and payload. */
+/* u32 vrt_sid; // Stream ID */
+/* }; */
+
+/* #define VRT_SIZE 8 */
+
+
+/*
+Ettus Research CHDR header
+NOTE: Little endian byte order (must be unswizzled)
+*/
+
+struct chdr_header {
+ u32 chdr_type;// [31] Ext Context, [30] RSVD, [29] Has_time, [28] EOB], [27:16] SEQ_ID, [15:0] Size
+ u32 chdr_sid; // Stream ID
+};
+
+#define CHDR_SIZE 8
+
+/*
+Break down SID into CHDR defined fields
+*/
+struct chdr_sid {
+ u8 src_device;
+ u8 src_endpoint;
+ u8 dst_device;
+ u8 dst_endpoint;
+};
+
+struct radio_ctrl_payload {
+ u32 addr;
+ u32 data;
+};
+
+struct radio_response {
+ u64 data;
+};
+
+struct tx_response {
+ u32 error_code;
+ u32 seq_id;
+};
+
+#define TX_ACK 0x00
+#define TX_EOB 0x01
+#define TX_UNDERRUN 0x02
+#define TX_SEQ_ERROR 0x04
+#define TX_TIME_ERROR 0x08
+#define TX_MIDBURST_SEQ_ERROR 0x20
+
+struct src_flow_ctrl {
+ u32 unused;
+ u32 seq_id;
+};
+
+struct vita_time {
+ u64 time;
+};
+
+#define VITA_TIME_SIZE 8
+#define RADIO_CTRL_SIZE 8
+#define RADIO_RESPONSE_SIZE 4
+
+
+/*
+ Packet storage
+*/
+
+struct pbuf {
+ struct pbuf *next;
+ struct pbuf *last;
+ struct timeval ts;
+ int size; // Size stored in pcap file
+ int orig_size; // Original capture size on the wire
+ char *payload;
+};
+
+struct pbuf_info {
+ struct pbuf *start;
+ struct pbuf *current;
+ struct pbuf *end;
+};
+
+struct radio_ctrl_names {
+ u32 addr;
+ char *name;
+};
+
+
+//
+// Prototypes
+//
+
+unsigned long swaplong (unsigned long);
+unsigned int swapint (unsigned int);
+unsigned short swapshort (unsigned short);
+char *format_gmt(const struct timeval *, char *);
+double timeval2double(struct timeval *);
+double relative_time(struct timeval *, struct timeval *);
+void get_packet(struct pbuf_info * , const struct pcap_pkthdr *, const u_char *);
+void get_start_time(struct timeval * , const struct pcap_pkthdr *, const u_char *);
+void get_udp_port_from_file(u16, const char *, struct pbuf_info *, struct timeval *);
+void get_everything_from_file(const char *, struct pbuf_info *, struct timeval *);
+void get_connection_endpoints( struct pbuf_info *, struct in_addr *, struct in_addr *);
+void print_direction(const struct pbuf_info *, const struct in_addr *, const struct in_addr *);
+void print_size( const struct pbuf_info *);
+void print_sid( const struct pbuf_info *);
+void print_vita_header( const struct pbuf_info *, const struct in_addr *);
+
+#endif
diff --git a/tools/uhd_dump/usrp3_regs.h b/tools/uhd_dump/usrp3_regs.h
new file mode 100644
index 000000000..5e3fc1cac
--- /dev/null
+++ b/tools/uhd_dump/usrp3_regs.h
@@ -0,0 +1,51 @@
+
+const struct radio_ctrl_names reg_list[] =
+ {
+ {5, "SR_DACSYNC"},
+ {6, "SR_LOOPBACK"},
+ {7, "SR_TEST"},
+ {8, "SR_SPI_DIVIDER"},
+ {9, "SR_SPI_CONFIG"},
+ {10, "SR_SPI_DATA"},
+ {16, "SR_GPIO_IDLE"},
+ {17, "SR_GPIO_RX"},
+ {18, "SR_GPIO_TX"},
+ {19, "SR_GPIO_FDX"},
+ {20, "SR_GPIO_DDR"},
+ {24, "SR_MISC_OUTS"},
+ {32, "SR_READBACK"},
+ {64, "SR_ERROR_POLICY"},
+ {66, "SR_CYCLES"},
+ {67, "SR_PACKETS"},
+ {96, "SR_RX_CTRL_CMD"},
+ {97, "SR_RX_CTRL_TIME_H"},
+ {98, "SR_RX_CTRL_TIME_L"},
+ {99, "SR_RX_CTRL_RX_HALT"},
+ {100, "SR_RX_CTRL_MAXLEN"},
+ {101, "SR_RX_CTRL_SID"},
+ {102, "SR_RX_CTRL_WINDOW_SIZE"},
+ {103, "SR_RX_CTRL_WINDOW_ENABLE"},
+ {128, "SR_TIME_HI"},
+ {129, "SR_TIME_LO"},
+ {130, "SR_TIME_CTRL"},
+ {144, "SR_RX_DSP_0"},
+ {145, "SR_RX_DSP_1"},
+ {146, "SR_RX_DSP_2"},
+ {147, "SR_RX_DSP_3"},
+ {184, "SR_TX_DSP_0"},
+ {185, "SR_TX_DSP_1"},
+ {186, "SR_TX_DSP_2"},
+ {196, "SR_LEDS_IDLE"},
+ {197, "SR_LEDS_RX"},
+ {198, "SR_LEDS_TX"},
+ {199, "SR_LEDS_FDX"},
+ {200, "SR_LEDS_DDR"},
+ {208, "SR_SWAP_IQ"},
+ {209, "SR_MAG_CORR"},
+ {210, "SR_PHASE_CORR"},
+ {211, "SR_RX_DC_OFFSET_I"},
+ {212, "SR_RX_DC_OFFSET_Q"},
+ {999, "NOT FOUND"}
+ }
+;
+