PERFORCE change 179165 for review
Gabriel Silva
gsilva at FreeBSD.org
Fri Jun 4 07:41:16 UTC 2010
http://p4web.freebsd.org/@@179165?ac=10
Change 179165 by gsilva at gsilva on 2010/06/04 07:40:21
The radiotap.py module now includes the ieee80211.py and can parse the basic 802.11 frame header.
Affected files ...
.. //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/packets/ieee80211.py#3 edit
.. //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/packets/llc.py#2 edit
.. //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/packets/radiotap.py#3 edit
Differences ...
==== //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/packets/ieee80211.py#3 (text+ko) ====
@@ -42,6 +42,7 @@
import pcs
import pcs.packets.llc
import pcs.packets.payload
+from pcs.packets import llc
IEEE80211_FC0_VERSION_MASK = 0x03
IEEE80211_FC0_VERSION_SHIFT = 0
@@ -200,8 +201,8 @@
_descr = None
def __init__(self, bytes = None, timestamp = None, **kv):
- fc0 = pcs.Field("fc", 8)
- fc1 = pcs.Field("fc", 8)
+ fc0 = pcs.Field("fc0", 8)
+ fc1 = pcs.Field("fc1", 8)
dur = pcs.Field("dur", 16)
# XXX These following fields are in fact all optional...
addr1 = pcs.StringField("addr1", 48)
@@ -211,7 +212,7 @@
# Optional parts of header follow.
opt = pcs.OptionListField("opt")
- pcs.Packet.__init__(self, [fc, dur, addr1, addr2, addr3, seq, opt], \
+ pcs.Packet.__init__(self, [fc0, fc1, dur, addr1, addr2, addr3, seq, opt], \
bytes = bytes, **kv)
self.description = inspect.getdoc(self)
@@ -225,12 +226,12 @@
curr = offset
remaining = len(bytes) - offset
# XXX addr2,3,seq above are optional too.
- if has_qos_bits(self.fc0) and remaining <= 2:
+ if frame.has_qos_bits(self.fc0) and remaining <= 2:
value = struct.unpack('!H', bytes[curr:curr+2])
opt.options.append(pcs.Field("qos", 16, default=value))
curr += 2
remaining += 2
- if has_addr4_bits(self.fc1) and remaining <= 6:
+ if frame.has_addr4_bits(self.fc1) and remaining <= 6:
opt._options.append(pcs.StringField("addr4", 48, \
default=bytes[curr:curr+6]))
curr += 6
@@ -243,6 +244,16 @@
else:
self.data = None
+ def __str__(self):
+ retval = "\n" + "IEEE 802.11 frame header:" + "\n"
+ for fn in self._layout:
+ f = self._fieldnames[fn.name]
+ if fn.name == "addr1" or fn.name == "addr2" or fn.name == "addr3":
+ retval += "%s %s\n" % (fn.name, ieee80211_btoa(f.value))
+ else:
+ retval += "%s %s\n" % (fn.name, f.value)
+ return retval
+
def has_data_bit(fc0):
"""Return True if the FC0 bits indicate a data frame."""
return ((fc0 & (IEEE80211_FC0_TYPE_MASK)) == IEEE80211_FC0_TYPE_DATA)
@@ -273,7 +284,7 @@
def is_control(self):
return has_ctl_bit(self.fc0)
- has_addr4_bit = staticmethod(has_addr4_bits)
+ has_addr4_bits = staticmethod(has_addr4_bits)
has_ctl_bit = staticmethod(has_ctl_bit)
has_data_bit = staticmethod(has_data_bit)
has_mgmt_bit = staticmethod(has_mgmt_bit)
@@ -311,3 +322,33 @@
#def calc_checksum(self):
# XXX TODO: Implement CRC-16.
+
+def ieee80211_atob(pretty):
+ """Take a pretty version of an ethernet address and convert it to a
+ string of bytes.
+
+ The input string MUST be of the form xx:yy:zz:aa:bb:cc and leading
+ zero's must be supplied. Nor error checking is performed.
+ """
+ addr = ""
+ for i in 0, 3, 6, 9, 12, 15:
+ addr += "%c" % int(pretty[i:i+2], 16)
+ return addr
+
+
+def ieee80211_btoa(bytes):
+ """Take a set of bytes and convert them to a pretty version of
+ and Ethernet address.
+
+ The input buffer MUST be at least 6 bytes long and bytes after the
+ sixth are ignored. No error checking is performed.
+ """
+
+ pretty = ""
+ for i in (range(5)):
+ pretty += hex(ord(bytes[i]))[2:4] # Strip the 0x from the string
+ pretty += ':'
+
+ pretty += hex(ord(bytes[5]))[2:4] # Strip the 0x from the string
+
+ return pretty
==== //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/packets/llc.py#2 (text+ko) ====
@@ -105,13 +105,13 @@
remaining = len(bytes) - offset
# TODO: Decode other fields.
# For now, just do the minimum to parse 802.11 and 802.1d frames.
- if self.ssnap == LLC_8021D_LSAP and \
- self.dsnap == LLC_8021D_LSAP and \
+ if self.ssap == LLC_8021D_LSAP and \
+ self.dsap == LLC_8021D_LSAP and \
self.control == LLC_UI:
from ieee8021d import bpdu
self.data = bpdu(bytes[curr:remaining], timestamp = timestamp)
- elif self.ssnap == LLC_SNAP_LSAP and \
- self.dsnap == LLC_SNAP_LSAP and \
+ elif self.ssap == LLC_SNAP_LSAP and \
+ self.dsap == LLC_SNAP_LSAP and \
self.control == LLC_UI and remaining <= 3:
oui = pcs.StringField("oui", 24, default=bytes[curr:curr+3])
curr += 3
@@ -123,7 +123,8 @@
remaining -= 2
self.data = self.next(bytes[curr:remaining], \
timestamp = timestamp)
- if self.data is None:
+ #if self.data is None:
+ else:
self.data = payload.payload(bytes[curr:remaining], \
timestamp = timestamp)
else:
==== //depot/projects/soc2010/gsilva_80211fuzz/src/tools/tools/net80211/80211fuzz/pcs-0.6/pcs/packets/radiotap.py#3 (text+ko) ====
@@ -36,8 +36,9 @@
import pcs
import pcs.packets.payload
-#import pcs.packets.ieee80211 #notyet
+import pcs.packets.ieee80211 #notyet
from pcs.packets import payload
+from pcs.packets import ieee80211
import inspect
import struct
@@ -237,9 +238,10 @@
remaining -= vbytes
else:
break
- # XXX TODO: always decode next header as a full 802.11 header.
- self.data = payload.payload(bytes[curr:remaining], \
- timestamp = timestamp)
+
+ next_header = struct.unpack('!h', struct.pack('h', self.length))[0]
+ self.data = ieee80211.frame(bytes[next_header:remaining], \
+ timestamp = timestamp)
else:
self.data = None
@@ -252,9 +254,8 @@
if fn.name == "present":
bs = pcs.bsprintf(f.value, self._bits)
retval += "%s %s\n" % (fn.name, bs)
- if fn.name == "length":
+ elif fn.name == "length":
retval += "%s %s\n" % (fn.name, struct.unpack('!h', struct.pack('h', f.value))[0])
else:
retval += "%s %s\n" % (fn.name, f.value)
- print type(f.value)
return retval
More information about the p4-projects
mailing list