Example #1
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = offset = self.offset + 4

                while (offset - init) < (self.length - 4):
                    (msg_type, length) = struct.unpack_from("BB", self.data, offset)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"], = struct.unpack_from("%is" % length, self.data, offset + 2)

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_rates(offset + 2, length)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        channel, = struct.unpack_from("B", self.data, offset + 2)
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_TIM:
                        self.value["TRAFFIC INDICATION MAP"] = self.binary_tim(offset + 2)

                    if msg_type == NL80211_BSS_ELEMENTS_EXTENDED_RATE:
                        extended_rates = self.binary_rates(offset + 2, length)
                        self.value["EXTENDED_RATES"] = extended_rates

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        self.value["VENDOR"], = struct.unpack_from("%is" % length, self.data, offset + 2)

                    offset += length
Example #2
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = self.buf.tell()

                while (self.buf.tell()-init) < (self.length-4):
                    (msg_type, length) = struct.unpack('BB', self.buf.read(2))
                    data = self.buf.read(length)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"] = data

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_rates(data)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        (channel,) = struct.unpack("B", data[0:1])
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_TIM:
                        self.value["TRAFFIC INDICATION MAP"] = \
                            self.binary_tim(data)

                    if msg_type == NL80211_BSS_ELEMENTS_EXTENDED_RATE:
                        extended_rates = self.binary_rates(data)
                        self.value["EXTENDED_RATES"] = extended_rates

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        self.binary_vendor(data)

                self.buf.seek(init)
Example #3
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = self.buf.tell()

                while (self.buf.tell() - init) < (self.length - 4):
                    (msg_type, length) = struct.unpack('BB', self.buf.read(2))
                    data = self.buf.read(length)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"] = data

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_rates(data)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        (channel, ) = struct.unpack("B", data[0:1])
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_TIM:
                        self.value["TRAFFIC INDICATION MAP"] = \
                            self.binary_tim(data)

                    if msg_type == NL80211_BSS_ELEMENTS_EXTENDED_RATE:
                        extended_rates = self.binary_rates(data)
                        self.value["EXTENDED_RATES"] = extended_rates

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        self.binary_vendor(data)

                self.buf.seek(init)
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = self.buf.tell()

                while (self.buf.tell() - init) < (self.length - 4):
                    (msg_type, length) = struct.unpack('BB', self.buf.read(2))
                    data = self.buf.read(length)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"] = data

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_supported_rates(data)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        (channel, ) = struct.unpack("B", data[0])
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        self.binary_vendor(data)

                    # if catch == 0:
                    #    self.value["NL80211_BSS_ELEMENTS_UNKNOWN"+str(msg_type)]=hexdump(data)

                self.buf.seek(init)
                # self.value["NL80211_BSS_ELEMENTS_HEXDUMP"] =
                # hexdump(self.buf.read(self.length))

                self.buf.seek(init)
Example #5
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = self.buf.tell()

                while (self.buf.tell()-init) < (self.length-4):
                    (msg_type, length) = struct.unpack('BB', self.buf.read(2))
                    data = self.buf.read(length)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"] = data

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_supported_rates(data)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        (channel,) = struct.unpack("B", data[0])
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        self.binary_vendor(data)

                    # if catch == 0:
                    #    self.value["NL80211_BSS_ELEMENTS_UNKNOWN"+str(msg_type)]=hexdump(data)

                self.buf.seek(init)
                # self.value["NL80211_BSS_ELEMENTS_HEXDUMP"] =
                # hexdump(self.buf.read(self.length))

                self.buf.seek(init)
Example #6
0
            def decode(self):
                nla_base.decode(self)

                offset = self.offset + 4
                self.value = {}
                tsf, = struct.unpack_from('Q', self.data, offset)
                self.value["VALUE"] = tsf
                # TSF is in microseconds
                self.value["TIME"] = datetime.timedelta(microseconds=tsf)
Example #7
0
 def decode(self):
   nla_base.decode(self)
   family = struct.unpack('H', self['value'][:2])[0]
   if family == AF_INET:
     port, host = struct.unpack('!H4s', self['value'][2:8])
     self.value = (inet_ntop(family, host), port)
   elif family == AF_INET6:
     port, flowinfo, host, scopeid = struct.unpack('!HI16sI', self['value'][2:28])
     self.value = (inet_ntop(family, host), port, flowinfo, scopeid)
Example #8
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = offset = self.offset + 4

                ie_class_map = {
                    NL80211_BSS_ELEMENTS_SSID: SSID,
                    NL80211_BSS_ELEMENTS_SUPPORTED_RATES: Supported_Rates,
                    NL80211_BSS_ELEMENTS_CHANNEL: DSSS_Parameter_Set,
                    NL80211_BSS_ELEMENTS_TIM: TIM,
                    NL80211_BSS_ELEMENTS_COUNTRY: Country,
                    NL80211_BSS_ELEMENTS_HT_CAPABILITIES: HT_Capabilities,
                    NL80211_BSS_ELEMENTS_RSN: RSN,
                    NL80211_BSS_ELEMENTS_EXTENDED_RATE: Extended_Rates,
                    NL80211_BSS_ELEMENTS_HT_OPERATION: HT_Operation,
                    NL80211_BSS_ELEMENTS_EXT_CAPABILITIES:
                    Extended_Capabilities,
                    NL80211_BSS_ELEMENTS_VHT_CAPABILITIES: VHT_Capabilities,
                    NL80211_BSS_ELEMENTS_VHT_OPERATION: VHT_Operation,
                    NL80211_BSS_ELEMENTS_VENDOR: Vendor_Specific,
                }

                while (offset - init) < (self.length - 4):
                    (msg_type,
                     length) = struct.unpack_from('BB', self.data, offset)

                    # TODO so I can keep keep an eye on what needs to be
                    # decoded
                    try:
                        msg_name = NL80211_BSS_ELEMENTS_VALUES[msg_type]
                    except KeyError:
                        log.warning("unhandled IE element type=%d", msg_type)
                        if "TODO" in self.value:
                            self.value["TODO"].append(msg_type)
                        else:
                            self.value["TODO"] = [
                                msg_type,
                            ]
                        offset += length + 2
                        continue

                    cls = ie_class_map[msg_type]
                    offset += 2
                    elem = cls(self.data[offset:offset + length])
                    elem.decode()
                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        if msg_name in self.value:
                            # append to existing vendorid
                            self.value[msg_name].append(elem.value)
                        else:
                            self.value[msg_name] = [elem.value]
                    else:
                        self.value[msg_name] = elem.value
                    offset += length
Example #9
0
            def decode(self):
                nla_base.decode(self)

                offset = self.offset + 4
                self.value = {}
                tsf, = struct.unpack_from('Q', self.data, offset)
                self.value["VALUE"] = tsf
                # TSF is in microseconds
                # TODO verify this won't overflow internally
                self.value["TIME"] = datetime.timedelta(microseconds=tsf)
Example #10
0
 def decode(self):
     nla_base.decode(self)
     offset = self.offset + 4
     self.value = {}
     ss, = struct.unpack_from('i', self.data, offset)
     self.value["VALUE"] = ss
     self.value["SIGNAL_STRENGTH"] = {
         "VALUE": ss / 100.0,
         "UNITS": "dBm"
     }
Example #11
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = offset = self.offset + 4

                while (offset - init) < (self.length - 4):
                    (msg_type, length) = struct.unpack_from('BB',
                                                            self.data,
                                                            offset)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"], = (struct
                                               .unpack_from('%is' % length,
                                                            self.data,
                                                            offset + 2))

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_rates(offset + 2, length)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        channel, = struct.unpack_from('B',
                                                      self.data,
                                                      offset + 2)
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_TIM:
                        self.value["TRAFFIC INDICATION MAP"] = \
                            self.binary_tim(offset + 2)

                    if msg_type == NL80211_BSS_ELEMENTS_RSN:
                        self.value["RSN"], = (struct
                                              .unpack_from('%is' % length,
                                                           self.data,
                                                           offset + 2))

                    if msg_type == NL80211_BSS_ELEMENTS_EXTENDED_RATE:
                        extended_rates = self.binary_rates(offset + 2, length)
                        self.value["EXTENDED_RATES"] = extended_rates

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        # There may be multiple vendor IEs, create a list
                        if "VENDOR" not in self.value.keys():
                            self.value["VENDOR"] = []
                        vendor_ie, = (struct.unpack_from('%is' % length,
                                                         self.data,
                                                         offset + 2))
                        self.value["VENDOR"].append(vendor_ie)

                    offset += length + 2
Example #12
0
            def decode(self):
                nla_base.decode(self)
                self.value = {}
                self.value["AUTHORIZED"] = False
                self.value["SHORT_PREAMBLE"] = False
                self.value["WME"] = False
                self.value["MFP"] = False
                self.value["AUTHENTICATED"] = False
                self.value["TDLS_PEER"] = False
                self.value["ASSOCIATED"] = False

                init = offset = self.offset + 4
                while (offset - init) < (self.length - 4):
                    (msg_type, length) = struct.unpack_from('BB',
                                                            self.data,
                                                            offset)
                    mask, set_ = struct.unpack_from('II',
                                                    self.data,
                                                    offset + 2)

                    if mask & NL80211_STA_FLAG_AUTHORIZED:
                        if set_ & NL80211_STA_FLAG_AUTHORIZED:
                            self.value["AUTHORIZED"] = True

                    if mask & NL80211_STA_FLAG_SHORT_PREAMBLE:
                        if set_ & NL80211_STA_FLAG_SHORT_PREAMBLE:
                            self.value["SHORT_PREAMBLE"] = True

                    if mask & NL80211_STA_FLAG_WME:
                        if set_ & NL80211_STA_FLAG_WME:
                            self.value["WME"] = True

                    if mask & NL80211_STA_FLAG_MFP:
                        if set_ & NL80211_STA_FLAG_MFP:
                            self.value["MFP"] = True

                    if mask & NL80211_STA_FLAG_AUTHENTICATED:
                        if set_ & NL80211_STA_FLAG_AUTHENTICATED:
                            self.value["AUTHENTICATED"] = True

                    if mask & NL80211_STA_FLAG_TDLS_PEER:
                        if set_ & NL80211_STA_FLAG_TDLS_PEER:
                            self.value["TDLS_PEER"] = True

                    if mask & NL80211_STA_FLAG_ASSOCIATED:
                        if set_ & NL80211_STA_FLAG_ASSOCIATED:
                            self.value["ASSOCIATED"] = True

                    offset += length + 2
Example #13
0
    def decode(self):
        nla_base.decode(self)
        family, = unpack_from("H", self["value"])

        try:
            type = {
                AF_INET: sockaddr_in,
                AF_INET6: sockaddr_in6,
            }[family]
        except:
            raise NotImplementedError

        if isinstance(self['value'], bytearray):
            self.value = type.from_buffer(self['value'])
        elif isinstance(self['value'], bytes):
            self.value = type.from_buffer_copy(self['value'])
Example #14
0
            def decode(self):
                nla_base.decode(self)
                self.value = {}
                self.value["AUTHORIZED"] = False
                self.value["SHORT_PREAMBLE"] = False
                self.value["WME"] = False
                self.value["MFP"] = False
                self.value["AUTHENTICATED"] = False
                self.value["TDLS_PEER"] = False
                self.value["ASSOCIATED"] = False

                init = offset = self.offset + 4
                while (offset - init) < (self.length - 4):
                    (msg_type,
                     length) = struct.unpack_from('BB', self.data, offset)
                    mask, set_ = struct.unpack_from('II', self.data,
                                                    offset + 2)

                    if mask & NL80211_STA_FLAG_AUTHORIZED:
                        if set_ & NL80211_STA_FLAG_AUTHORIZED:
                            self.value["AUTHORIZED"] = True

                    if mask & NL80211_STA_FLAG_SHORT_PREAMBLE:
                        if set_ & NL80211_STA_FLAG_SHORT_PREAMBLE:
                            self.value["SHORT_PREAMBLE"] = True

                    if mask & NL80211_STA_FLAG_WME:
                        if set_ & NL80211_STA_FLAG_WME:
                            self.value["WME"] = True

                    if mask & NL80211_STA_FLAG_MFP:
                        if set_ & NL80211_STA_FLAG_MFP:
                            self.value["MFP"] = True

                    if mask & NL80211_STA_FLAG_AUTHENTICATED:
                        if set_ & NL80211_STA_FLAG_AUTHENTICATED:
                            self.value["AUTHENTICATED"] = True

                    if mask & NL80211_STA_FLAG_TDLS_PEER:
                        if set_ & NL80211_STA_FLAG_TDLS_PEER:
                            self.value["TDLS_PEER"] = True

                    if mask & NL80211_STA_FLAG_ASSOCIATED:
                        if set_ & NL80211_STA_FLAG_ASSOCIATED:
                            self.value["ASSOCIATED"] = True

                    offset += length + 2
Example #15
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = offset = self.offset + 4

                while (offset - init) < (self.length - 4):
                    (msg_type,
                     length) = struct.unpack_from('BB', self.data, offset)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"], = (struct.unpack_from(
                            '%is' % length, self.data, offset + 2))

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_rates(offset + 2, length)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        channel, = struct.unpack_from('B', self.data,
                                                      offset + 2)
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_TIM:
                        self.value["TRAFFIC INDICATION MAP"] = \
                            self.binary_tim(offset + 2)

                    if msg_type == NL80211_BSS_ELEMENTS_RSN:
                        self.value["RSN"], = (struct.unpack_from(
                            '%is' % length, self.data, offset + 2))

                    if msg_type == NL80211_BSS_ELEMENTS_EXTENDED_RATE:
                        extended_rates = self.binary_rates(offset + 2, length)
                        self.value["EXTENDED_RATES"] = extended_rates

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        # There may be multiple vendor IEs, create a list
                        if "VENDOR" not in self.value.keys():
                            self.value["VENDOR"] = []
                        vendor_ie, = (struct.unpack_from(
                            '%is' % length, self.data, offset + 2))
                        self.value["VENDOR"].append(vendor_ie)

                    offset += length + 2
Example #16
0
            def decode(self):
                nla_base.decode(self)

                offset = self.offset + 4
                self.value = {}
                capa, = struct.unpack_from('H', self.data, offset)
                self.value["VALUE"] = capa

                s = []
                if capa & self.WLAN_CAPABILITY_ESS:
                    s.append("ESS")
                if capa & self.WLAN_CAPABILITY_IBSS:
                    s.append("IBSS")
                if capa & self.WLAN_CAPABILITY_CF_POLLABLE:
                    s.append("CfPollable")
                if capa & self.WLAN_CAPABILITY_CF_POLL_REQUEST:
                    s.append("CfPollReq")
                if capa & self.WLAN_CAPABILITY_PRIVACY:
                    s.append("Privacy")
                if capa & self.WLAN_CAPABILITY_SHORT_PREAMBLE:
                    s.append("ShortPreamble")
                if capa & self.WLAN_CAPABILITY_PBCC:
                    s.append("PBCC")
                if capa & self.WLAN_CAPABILITY_CHANNEL_AGILITY:
                    s.append("ChannelAgility")
                if capa & self.WLAN_CAPABILITY_SPECTRUM_MGMT:
                    s.append("SpectrumMgmt")
                if capa & self.WLAN_CAPABILITY_QOS:
                    s.append("QoS")
                if capa & self.WLAN_CAPABILITY_SHORT_SLOT_TIME:
                    s.append("ShortSlotTime")
                if capa & self.WLAN_CAPABILITY_APSD:
                    s.append("APSD")
                if capa & self.WLAN_CAPABILITY_RADIO_MEASURE:
                    s.append("RadioMeasure")
                if capa & self.WLAN_CAPABILITY_DSSS_OFDM:
                    s.append("DSSS-OFDM")
                if capa & self.WLAN_CAPABILITY_DEL_BACK:
                    s.append("DelayedBACK")
                if capa & self.WLAN_CAPABILITY_IMM_BACK:
                    s.append("ImmediateBACK")

                self.value['CAPABILITIES'] = " ".join(s)
Example #17
0
            def decode(self):
                nla_base.decode(self)

                self.value = {}

                init = offset = self.offset + 4

                while (offset - init) < (self.length - 4):
                    (msg_type,
                     length) = struct.unpack_from('BB', self.data, offset)
                    if msg_type == NL80211_BSS_ELEMENTS_SSID:
                        self.value["SSID"], = (struct.unpack_from(
                            '%is' % length, self.data, offset + 2))

                    if msg_type == NL80211_BSS_ELEMENTS_SUPPORTED_RATES:
                        supported_rates = self.binary_rates(offset + 2, length)
                        self.value["SUPPORTED_RATES"] = supported_rates

                    if msg_type == NL80211_BSS_ELEMENTS_CHANNEL:
                        channel, = struct.unpack_from('B', self.data,
                                                      offset + 2)
                        self.value["CHANNEL"] = channel

                    if msg_type == NL80211_BSS_ELEMENTS_TIM:
                        self.value["TRAFFIC INDICATION MAP"] = \
                            self.binary_tim(offset + 2)

                    if msg_type == NL80211_BSS_ELEMENTS_EXTENDED_RATE:
                        extended_rates = self.binary_rates(offset + 2, length)
                        self.value["EXTENDED_RATES"] = extended_rates

                    if msg_type == NL80211_BSS_ELEMENTS_VENDOR:
                        self.value["VENDOR"], = (struct.unpack_from(
                            '%is' % length, self.data, offset + 2))

                    offset += length + 2
Example #18
0
File: key.py Project: r1b/wgnlpy
 def decode(self):
     nla_base.decode(self)
     self.value = self['value'] if self['value'] != bytes(32) else None
Example #19
0
 def decode(self):
     nla_base.decode(self)
     tv_sec = int(self['tv_sec'])
     tv_nsec = int(self['tv_nsec']) / 1e9
     self.value = tv_sec + tv_nsec
Example #20
0
 def decode(self):
   nla_base.decode(self)
   sec, _ = struct.unpack('ll', self['value'])
   self.value = datetime.datetime.fromtimestamp(sec)