Bbn_80211b_rx.py: how is the received packet handled please?

Hello,

In the BBN 802.11 package, I see the scripts for receiver, and some
lines of
code for packet handling as well.

======================================================
def rx_callback(ok, payload):
size = struct.calcsize(“@qHBB”);
packet_data = payload[size:];
hdr = struct.unpack(“@qHbB”, payload[0:size]);
if len(packet_data) > 16:
data_hdr = struct.unpack(“@BBBBBB”, packet_data[10:16])
mac_str = “%02x:%02x:%02x:%02x:%02X:%02X” %
(data_hdr[0], data_hdr[1], data_hdr[2],
data_hdr[3], data_hdr[4], data_hdr[5],)
else:
mac_str = “UNKNOWN”

print "PKT: len=%d, rssi=%d, src=%s, time=%ld, rate=%d Mbps" \
      % (hdr[1], hdr[2], mac_str, hdr[0], hdr[3]/ 10.0)

=======================================================

What does the struct.unpack do? Is it for formatting the packet for
display?
coz when I tried to do this: print “payload: %s” % payload, what got
displayed on the screen is like this:
payload: �,Q
�������F(�F(�p��j{Yd!
䀹����
0H
*2$`l�
And what exactly the “time” is? As I see in the script, is it in ticks?
means the time instance, or the inter-arrival time?

View this message in context:
http://www.nabble.com/bbn_80211b_rx.py%3A-how-is-the-received-packet-handled-please--tp18720769p18720769.html
Sent from the GnuRadio mailing list archive at Nabble.com.

Inlined responses:

Quoting yyzhuang [email protected]:

Hello,

Hi,

In the BBN 802.11 package, I see the scripts for receiver, and some lines of
code for packet handling as well.

======================================================
def rx_callback(ok, payload):
size = struct.calcsize(“@qHBB”);
packet_data = payload[size:];
hdr = struct.unpack(“@qHbB”, payload[0:size]);
if len(packet_data) > 16:
data_hdr = struct.unpack(“@BBBBBB”, packet_data[10:16])

What does the struct.unpack do? Is it for formatting the packet for display?

Pretty much – though it does more than that as well.

struct.unpack() is also used by the mainline gnuradio code (see
gnuradio-examples/python/(digital|ofdm)/benchmark_* for instance).

coz when I tried to do this: print “payload: %s” % payload, what got
displayed on the screen is like this:
payload:

That’s because the ‘payload’ string isn’t ascii- or unicode-formatted;
it’s raw binary data packed into a string because that’s how python
handles things that would be stored in a c struct.
If you unpack it with an appropriate format string, you can display
the actual data received. (something close to but less ugly than
struct.unpack(‘!’ + len(payload) + ‘B’,payload)
depending on what you want to see.)

And what exactly the “time” is? As I see in the script, is it in ticks?
means the time instance, or the inter-arrival time?

I’ll defer to someone who’s familiar with the BBN code.

–Mason

At 04:33 PM 7/29/2008, yyzhuang wrote:

And what exactly the “time” is? As I see in the script, is it in ticks?
means the time instance, or the inter-arrival time?

“time” is a packet arrival timestamp, in microseconds, relative to the
time
the receiver is started. It is calculated by counting received samples
so
it based off a clock in the USRP, not a clock in the PC. By comparing
the
timestamps of two received packets you should be able to determine
difference in actual arrival times to with a couple microseconds.

-Dan

Thanks. I think it should be something from the 802.11 frame over the
wireless link.

Since I see the time and other stuff are got from the packet, could
you tell me how is the packet received from usrp (by sampling in the
usrp?), what is its format? and for how we can actually do with it, is
unpack the packet according to its format enough?

Thanks again

Daniel Sumorok wrote:

timestamps of two received packets you should be able to determine


View this message in context:
http://www.nabble.com/bbn_80211b_rx.py%3A-how-is-the-received-packet-handled-please--tp18720769p18724383.html
Sent from the GnuRadio mailing list archive at Nabble.com.

Quoting “Y. Zhuang” [email protected]:

Thanks very much for help. So “@qHBB” and “@qHbB” actually mean the
format that we should unpack this string, right? What is the
differences between “@qHBB” and “@qHbB” then? and “@BBBBBB”?

Thank you

 Yes. Basically, to summarize the python doc I linked, if you have

binary data stored in a string you want to decode, each character in
the python format string corresponds to one or more of the bytes in it
(with the exception of the @ at the beginning. @ tells the byte order
and alignment to use – the system default in this case). Then q would
be a long long, H an unsigned short, and B being an unsigned char.
Also, @BBBBBB can be written as @6B, and you can construct the
formatting strings dynamically if needed (if transmitting a variable
length packet).

 The difference between qHbB and qHBB is that the lowercase b in

the middle is signed and the capital B is unsigned. (i.e. is the
number stored in two’s-complement.) Of course, what that means for the
code is up to the coder.

–Mason

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Jul 29, 2008, at 6:14 PM, yyzhuang wrote:

That’s the point. But to unpack a packet, we have to know exactly
its format.
Hope someone can tell what format of the packet is. And what
information can
we get from the packets.

The 802.11 packet format is non-trivial. You’ll want to look at the
spec for that. It’s available for free download @

If I had one piece of advice, it would be “be careful of endianness”

  • -Dan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkiPwhoACgkQy9GYuuMoUJ7wbACfUJsoUULKhZWR0oe8tL7y4aPQ
m5cAoLsdscdjvGVao6OHUMEkaE908QgB
=FQ73
-----END PGP SIGNATURE-----

That’s the point. But to unpack a packet, we have to know exactly its
format.
Hope someone can tell what format of the packet is. And what information
can
we get from the packets.

Thanks everybody =^D

Mason-29 wrote:

 Yes. Basically, to summarize the python doc I linked, if you have  

the middle is signed and the capital B is unsigned. (i.e. is the
[email protected]
Discuss-gnuradio Info Page


View this message in context:
http://www.nabble.com/bbn_80211b_rx.py%3A-how-is-the-received-packet-handled-please--tp18720769p18724417.html
Sent from the GnuRadio mailing list archive at Nabble.com.