summaryrefslogtreecommitdiffstats
path: root/host/lib
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-05 16:35:44 -0700
committerJosh Blum <josh@joshknows.com>2010-07-05 16:35:44 -0700
commitc2039a8c92561fa5532d87cb9d875a3ad7b875c1 (patch)
tree231b1c4cc8d4576f857177f5f4e190aed9fcaca8 /host/lib
parent8047f25c601c43d6941cd0d094360a56917917c8 (diff)
downloaduhd-c2039a8c92561fa5532d87cb9d875a3ad7b875c1.tar.gz
uhd-c2039a8c92561fa5532d87cb9d875a3ad7b875c1.tar.bz2
uhd-c2039a8c92561fa5532d87cb9d875a3ad7b875c1.zip
uhd: code tweaks, extra error condition for vrt unpack
Diffstat (limited to 'host/lib')
-rwxr-xr-xhost/lib/transport/gen_vrt_if_packet.py7
-rw-r--r--host/lib/transport/udp_zero_copy_asio.cpp2
-rw-r--r--host/lib/transport/vrt_packet_handler.hpp4
3 files changed, 8 insertions, 5 deletions
diff --git a/host/lib/transport/gen_vrt_if_packet.py b/host/lib/transport/gen_vrt_if_packet.py
index 536409b2e..7910ff60d 100755
--- a/host/lib/transport/gen_vrt_if_packet.py
+++ b/host/lib/transport/gen_vrt_if_packet.py
@@ -150,10 +150,10 @@ void vrt::if_hdr_unpack_$(suffix)(
if_packet_info.packet_count = (vrt_hdr_word >> 16) & 0xf;
//failure cases
- if (packet_words32 == 0 or if_packet_info.num_packet_words32 < packet_words32)
+ if (if_packet_info.num_packet_words32 < packet_words32)
throw std::runtime_error("bad vrt header or packet fragment");
if (vrt_hdr_word & (0x7 << 29))
- throw std::runtime_error("unsupported vrt packet type");
+ throw std::runtime_error("bad vrt header or unsupported packet type");
boost::uint8_t pred = 0;
if(vrt_hdr_word & $hex(0x1 << 28)) pred |= $hex($sid_p);
@@ -209,6 +209,9 @@ void vrt::if_hdr_unpack_$(suffix)(
#set $num_trailer_words = 0;
#end if
########## Variables ##########
+ //another failure case
+ if (packet_words32 < $($num_header_words + $num_trailer_words))
+ throw std::runtime_error("bad vrt header or invalid packet length");
if_packet_info.num_header_words32 = $num_header_words;
if_packet_info.num_payload_words32 = packet_words32 - $($num_header_words + $num_trailer_words);
break;
diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp
index 7f9292d24..a91be25af 100644
--- a/host/lib/transport/udp_zero_copy_asio.cpp
+++ b/host/lib/transport/udp_zero_copy_asio.cpp
@@ -28,7 +28,7 @@ using namespace uhd::transport;
* Constants
**********************************************************************/
//enough buffering for half a second of samples at full rate on usrp2
-static const size_t MIN_SOCK_BUFF_SIZE = size_t(sizeof(boost::uint32_t) * 25e6 * 0.5);
+static const size_t MIN_SOCK_BUFF_SIZE(sizeof(boost::uint32_t) * 25e6 * 0.5);
static const size_t MAX_DGRAM_SIZE = 1500; //assume max size on send and recv
static const double RECV_TIMEOUT = 0.1; //100 ms
diff --git a/host/lib/transport/vrt_packet_handler.hpp b/host/lib/transport/vrt_packet_handler.hpp
index 177239509..68edeb1e1 100644
--- a/host/lib/transport/vrt_packet_handler.hpp
+++ b/host/lib/transport/vrt_packet_handler.hpp
@@ -87,7 +87,7 @@ namespace vrt_packet_handler{
uhd::transport::vrt::if_packet_info_t if_packet_info;
for (size_t i = 0; i < state.width; i++){
const boost::uint32_t *vrt_hdr = state.managed_buffs[i]->cast<const boost::uint32_t *>() + vrt_header_offset_words32;
- if_packet_info.num_packet_words32 = num_packet_words32;
+ if_packet_info.num_packet_words32 = num_packet_words32 - vrt_header_offset_words32;
vrt_unpacker(vrt_hdr, if_packet_info);
//handle the packet count / sequence number
@@ -163,7 +163,7 @@ namespace vrt_packet_handler{
);
//update the rx copy buffer to reflect the bytes copied
- state.copy_buffs[i] = reinterpret_cast<const boost::uint8_t *>(state.copy_buffs[i]) + bytes_to_copy;
+ state.copy_buffs[i] += bytes_to_copy;
}
//update the copy buffer's availability
state.size_of_copy_buffs -= bytes_to_copy;