def __init__(self, data): self._frame_size = len(data) # Essential fields on the data frame # Field ----------- Size # frame control --- 2 B # duration -------- 2 B # destination ----- 6 B # source ---------- 6 B # bssid ----------- 6 B # sequence ctrl --- 2 B if self._frame_size < DOT11_DATA_FRAME_FIELDS_SIZE: raise IndexError("Frame to short.") index = 0 self._fc = FrameControl(data) index += 2 self._duration = data[index:index + 2] index += 2 # Addresses self._destination = helpers.bytes_to_mac_address(data[index:index + 6]) index += 6 self._source = helpers.bytes_to_mac_address(data[index:index + 6]) index += 6 self._bssid = helpers.bytes_to_mac_address(data[index:index + 6]) index += 6 seqctrl = struct.unpack("H", data[index:index + 2])[0] self._fragment = (seqctrl & 0x000F) self._sequence = (seqctrl & 0xFFF0) >> 4
def _process(self, data): '''Process Probe Request frame fields.''' self._frameControl = FrameControl(data[:2]) if self._frameControl.getType() != TYPE_MANAGEMENT: raise Exception("Invalid Frame Type.") if self._frameControl.getSubtype() != SUBTYPE_MANAGEMENT_PROBE_REQ: raise Exception("Invalid Frame Subtype.") self._duration = struct.unpack("H", data[2:4])[0] self._destination = helpers.bytes_to_mac_address(data[4:10]) self._source = helpers.bytes_to_mac_address(data[10:16]) self._bssid = helpers.bytes_to_mac_address(data[16:22]) # Process sequence control field seqctrl = struct.unpack("H", data[22:24])[0] self._fragment = (seqctrl & 0x000F) self._sequence = (seqctrl & 0xFFF0) >> 4 if self._frame_size > DOT11_PROBE_REQUEST_FRAME_FIELDS_SIZE + FCS_SIZE: # To get the offset of the information elements we need to go # to the end offset of the essential fields of the beacon frame # up to the end of the frame substracting the 4 bytes of the FCS. ie_data = data[DOT11_BEACON_FRAME_FIELDS_SIZE:-4] self._processInformationElements(ie_data)
def __init__(self, data): self._frame_size = len(data) # Essential fields on the data frame # Field ----------- Size # frame control --- 2 B # duration -------- 2 B # address1 -------- 6 B # address2 -------- 6 B # address3 -------- 6 B # sequence ctrl --- 2 B # address4 -------- 6 B (optional) if self._frame_size < DOT11_DATA_FRAME_FIELDS_SIZE: raise IndexError("Frame to short.") index = 0 self._fc = FrameControl(data) index += 2 self._duration = data[index:index + 2] index += 2 self._ibss = False self._infrastructure = False self._wds = False # Addresses self._address1 = helpers.bytes_to_mac_address(data[index:index + 6]) index += 6 self._address2 = helpers.bytes_to_mac_address(data[index:index + 6]) index += 6 self._address3 = helpers.bytes_to_mac_address(data[index:index + 6]) index += 6 to_ds = self._fc.getToDs() from_ds = self._fc.getFromDs() # IBSS if not to_ds and not from_ds: self._ibss = True self._destination = self._address1 self._source = self._address2 self._bssid = self._address3 # Infrastructure if (to_ds and not from_ds) or (not to_ds and from_ds): self._infrastructure = True if (to_ds and not from_ds): self._bssid = self._address1 self._source = self._address2 self._destination = self._address3 else: self._destination = self._address1 self._bssid = self._address2 self._source = self._address3 # WDS if to_ds and from_ds: self._address4 = helpers.bytes_to_mac_address(data[index:index + 6]) index += 6 self._wds = True self._bssid = self._address1 self._destination = self._address3 self._source = self._address4 seqctrl = struct.unpack("H", data[index:index + 2])[0] self._fragment = (seqctrl & 0x000F) self._sequence = (seqctrl & 0xFFF0) >> 4