示例#1
0
	def handle(self, msg, arg):
		try:
			e, attrs = py_genlmsg_parse(nlmsg_hdr(msg), 0, nl80211.ATTR_MAX, None)
			self.store_attrs(attrs)
			return NL_SKIP
		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print(v.message)
			traceback.print_tb(tb)
示例#2
0
	def handle(self, msg, arg):
		try:
			e, attrs = genl.py_genlmsg_parse(nl.nlmsg_hdr(msg), 0, nl80211.ATTR_MAX, None)
			self.store_attrs(attrs)
			return nl.NL_SKIP
		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print v.message
			traceback.print_tb(tb)
示例#3
0
	def handle(self, msg, arg):
		try:
			e, attrs = py_genlmsg_parse(nlmsg_hdr(msg), 0, nl80211.ATTR_MAX, None)
			sta = factory.get_inst().create(station, self._ifidx, None, self._access, attrs)
			s = self.store_station(sta)
			return NL_SKIP
		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print v.message
			traceback.print_tb(tb)
示例#4
0
文件: scan.py 项目: miguelhdo/py80211
	def handle(self, msg, arg):
		try:
			e, attrs = genl.py_genlmsg_parse(nl.nlmsg_hdr(msg), 0, nl80211.ATTR_MAX, None)
			if not nl80211.ATTR_BSS in attrs:
				return
			e, nattrs = nl.py_nla_parse_nested(len(bss_policy), attrs[nl80211.ATTR_BSS], bss_policy)
			self._bss.append(factory.get_inst().create(bss, nattrs, bss_policy))
		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print v.message
			traceback.print_tb(tb)
		return nl.NL_SKIP
示例#5
0
文件: base.py 项目: arend/py80211
	def _protocol_feature_handler(self, m, a):
                try:
                        e, attrs = py_genlmsg_parse(nlmsg_hdr(m), 0, nl80211.ATTR_MAX, None)
			if nl80211.ATTR_PROTOCOL_FEATURES in attrs:
				self._features = nla_get_u32(attrs[nl80211.ATTR_PROTOCOL_FEATURES])
                        return NL_SKIP
                except Exception as e:
                        (t,v,tb) = sys.exc_info()
                        print v.message
                        traceback.print_tb(tb)

		pass
示例#6
0
	def _protocol_feature_handler(self, m, a):
                try:
                        e, attrs = py_genlmsg_parse(nlmsg_hdr(m), 0, nl80211.ATTR_MAX, None)
			if nl80211.ATTR_PROTOCOL_FEATURES in attrs:
				self._features = nla_get_u32(attrs[nl80211.ATTR_PROTOCOL_FEATURES])
                        return NL_SKIP
                except Exception as e:
                        (t,v,tb) = sys.exc_info()
                        print(v.message)
                        traceback.print_tb(tb)

		pass
示例#7
0
def msg_handler(m, a):
    try:
        e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
                                        nl80211.NL80211_ATTR_MAX, None)
        if nl80211.NL80211_ATTR_WIPHY in attr:
            thiswiphy = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY])
            print("phy#%d" % thiswiphy)
        if nl80211.NL80211_ATTR_IFNAME in attr:
            print("\tinterface %s" %
                  nl.nla_get_string(attr[nl80211.NL80211_ATTR_IFNAME]))
        if nl80211.NL80211_ATTR_IFINDEX in attr:
            print("\tifindex %d" %
                  nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFINDEX]))
        if nl80211.NL80211_ATTR_WDEV in attr:
            print("\twdev 0x%lx" %
                  nl.nla_get_u64(attr[nl80211.NL80211_ATTR_WDEV]))
        if nl80211.NL80211_ATTR_MAC in attr:
            print("\tmac %02x:%02x:%02x:%02x:%02x:%02x" %
                  tuple(nl.nla_data(attr[nl80211.NL80211_ATTR_MAC])))
        if nl80211.NL80211_ATTR_SSID in attr:
            print("\tssid ", nl.nla_data(attr[nl80211.NL80211_ATTR_SSID]))
        if nl80211.NL80211_ATTR_IFTYPE in attr:
            iftype = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFTYPE])
            print("\ttype %s" % nl80211.nl80211_iftype2str[iftype])
        if nl80211.NL80211_ATTR_WIPHY_FREQ in attr:
            freq = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY_FREQ])

            sys.stdout.write("\tfreq %d MHz" % freq)

            if nl80211.NL80211_ATTR_CHANNEL_WIDTH in attr:
                chanw = nl.nla_get_u32(
                    attr[nl80211.NL80211_ATTR_CHANNEL_WIDTH])
                sys.stdout.write(", width: %s" %
                                 nl80211.nl80211_chan_width2str[chanw])
                if nl80211.NL80211_ATTR_CENTER_FREQ1 in attr:
                    sys.stdout.write(", center1: %d MHz" % nl.nla_get_u32(
                        attr[nl80211.NL80211_ATTR_CENTER_FREQ1]))
                if nl80211.NL80211_ATTR_CENTER_FREQ2 in attr:
                    sys.stdout.write(", center2: %d MHz" % nl.nla_get_u32(
                        attr[nl80211.NL80211_ATTR_CENTER_FREQ2]))
            elif nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE in attr:
                channel_type = nl.nla_get_u32(
                    attr[nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE])
                sys.stdout.write(
                    " %s" % nl80211.nl80211_channel_type2str(channel_type))

            sys.stdout.write("\n")
        return nl.NL_SKIP
    except Exception as e:
        (t, v, tb) = sys.exc_info()
        print v.message
        traceback.print_tb(tb)
示例#8
0
	def handle(self, msg, arg):
		try:
			e, attrs = genl.py_genlmsg_parse(nl.nlmsg_hdr(msg), 0, nl80211.ATTR_MAX, None)
			if nl80211.ATTR_WDEV in attrs:
				wdevid = nl.nla_get_u64(attrs[nl80211.ATTR_WDEV])
				if wdevid in self._iface.keys():
					self._iface[wdevid].store_attrs(attrs)
				else:
					iface = factory.get_inst().create(interface, self._access, attrs)
					self._iface[iface.wdevid] = iface
			return nl.NL_SKIP
		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print v.message
			traceback.print_tb(tb)
示例#9
0
	def handle(self, msg, arg):
		try:
			e, attrs = genl.py_genlmsg_parse(nl.nlmsg_hdr(msg), 0, nl80211.ATTR_MAX, None)
			if nl80211.ATTR_WIPHY in attrs:
				phynum = nl.nla_get_u32(attrs[nl80211.ATTR_WIPHY])
				if phynum in self._wiphy.keys():
					self._wiphy[phynum].store_attrs(attrs)
				else:
					phy = factory.get_inst().create(wiphy, self._access, attrs)
					self._wiphy[phy.phynum] = phy
			return nl.NL_SKIP
		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print v.message
			traceback.print_tb(tb)
示例#10
0
	def handle(self, msg, arg):
		try:
			e, attrs = genl.py_genlmsg_parse(nl.nlmsg_hdr(msg), 0, nl80211.ATTR_MAX, None)
			if nl80211.ATTR_WIPHY in attrs:
				phynum = nl.nla_get_u32(attrs[nl80211.ATTR_WIPHY])
				if phynum in self._wiphy.keys():
					self._wiphy[phynum].store_attrs(attrs)
				else:
					phy = wiphy(self._access, attrs)
					self._wiphy[phy.phynum] = phy
			return nl.NL_SKIP
		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print v.message
			traceback.print_tb(tb)
示例#11
0
 def handle(self, msg, arg):
     try:
         e, attrs = py_genlmsg_parse(nlmsg_hdr(msg), 0, nl80211.ATTR_MAX,
                                     None)
         if not nl80211.ATTR_BSS in attrs:
             return
         e, nattrs = py_nla_parse_nested(len(bss_policy),
                                         attrs[nl80211.ATTR_BSS],
                                         bss_policy)
         self._bss.append(factory.get_inst().create(bss, nattrs,
                                                    bss_policy))
     except Exception as e:
         (t, v, tb) = sys.exc_info()
         print(v.message)
         traceback.print_tb(tb)
     return NL_SKIP
示例#12
0
 def handle(self, msg, arg):
     try:
         e, attrs = py_genlmsg_parse(nlmsg_hdr(msg), 0, nl80211.ATTR_MAX,
                                     None)
         if nl80211.ATTR_WDEV in attrs:
             wdevid = nla_get_u64(attrs[nl80211.ATTR_WDEV])
             if wdevid in self._iface.keys():
                 self._iface[wdevid].store_attrs(attrs)
             else:
                 iface = factory.get_inst().create(interface, self._access,
                                                   attrs)
                 self._iface[iface.wdevid] = iface
         return NL_SKIP
     except Exception as e:
         (t, v, tb) = sys.exc_info()
         print v.message
         traceback.print_tb(tb)
示例#13
0
def msg_handler(m, a):
    try:
        e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
                                        nl80211.NL80211_ATTR_MAX, None)
        if nl80211.NL80211_ATTR_WIPHY_NAME in attr:
            print('wiphy %s' %
                  nl.nla_get_string(attr[nl80211.NL80211_ATTR_WIPHY_NAME]))
        if nl80211.NL80211_ATTR_WIPHY_BANDS in attr:
            fpol = nl.nla_policy_array(nl80211.NL80211_FREQUENCY_ATTR_MAX + 1)
            fpol[nl80211.NL80211_FREQUENCY_ATTR_FREQ].type = nl.NLA_U32
            fpol[nl80211.NL80211_FREQUENCY_ATTR_DISABLED].type = nl.NLA_FLAG
            fpol[
                nl80211.NL80211_FREQUENCY_ATTR_PASSIVE_SCAN].type = nl.NLA_FLAG
            fpol[nl80211.NL80211_FREQUENCY_ATTR_NO_IBSS].type = nl.NLA_FLAG
            fpol[nl80211.NL80211_FREQUENCY_ATTR_RADAR].type = nl.NLA_FLAG
            fpol[nl80211.NL80211_FREQUENCY_ATTR_MAX_TX_POWER].type = nl.NLA_U32

            nattrs = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_WIPHY_BANDS])
            for nattr in nattrs:
                handle_band(nattr, fpol)
        if nl80211.NL80211_ATTR_CIPHER_SUITES in attr:
            ciphers = nl.nla_data(attr[nl80211.NL80211_ATTR_CIPHER_SUITES])
            num = len(ciphers) / 4
            if num > 0:
                print("\tSupported Ciphers:")
                for i in range(0, num, 4):
                    print("\t\t* %s" % cipher_name(ciphers[i:i + 4]))
        if nl80211.NL80211_ATTR_SUPPORTED_IFTYPES in attr:
            print("\tSupported interface modes:")
            ifattr = nl.nla_get_nested(
                attr[nl80211.NL80211_ATTR_SUPPORTED_IFTYPES])
            for nl_mode in ifattr:
                print("\t\t* %s" %
                      nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
        if nl80211.NL80211_ATTR_SOFTWARE_IFTYPES in attr:
            print("\tsoftware interface modes (can always be added):")
            ifattr = nl.nla_get_nested(
                attr[nl80211.NL80211_ATTR_SOFTWARE_IFTYPES])
            for nl_mode in ifattr:
                print("\t\t* %s" %
                      nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
        return nl.NL_SKIP
    except Exception as e:
        (t, v, tb) = sys.exc_info()
        print v.message
        traceback.print_tb(tb)
示例#14
0
def msg_handler(m, a):
	try:
		e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
						nl80211.NL80211_ATTR_MAX, None)
		if nl80211.NL80211_ATTR_WIPHY in attr:
			thiswiphy = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY])
			print("phy#%d" % thiswiphy)
		if nl80211.NL80211_ATTR_IFNAME in attr:
			print("\tinterface %s" % nl.nla_get_string(attr[nl80211.NL80211_ATTR_IFNAME]));
		if nl80211.NL80211_ATTR_IFINDEX in attr:
			print("\tifindex %d" % nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFINDEX]))
		if nl80211.NL80211_ATTR_WDEV in attr:
			print("\twdev 0x%lx" % nl.nla_get_u64(attr[nl80211.NL80211_ATTR_WDEV]))
		if nl80211.NL80211_ATTR_MAC in attr:
			print("\tmac %02x:%02x:%02x:%02x:%02x:%02x" % tuple(nl.nla_data(attr[nl80211.NL80211_ATTR_MAC])))
		if nl80211.NL80211_ATTR_SSID in attr:
			print("\tssid ", nl.nla_data(attr[nl80211.NL80211_ATTR_SSID]))
		if nl80211.NL80211_ATTR_IFTYPE in attr:
			iftype = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_IFTYPE])
			print("\ttype %s" % nl80211.nl80211_iftype2str[iftype])
		if nl80211.NL80211_ATTR_WIPHY_FREQ in attr:
			freq = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY_FREQ])

			sys.stdout.write("\tfreq %d MHz" % freq);

			if nl80211.NL80211_ATTR_CHANNEL_WIDTH in attr:
				chanw = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_CHANNEL_WIDTH])
				sys.stdout.write(", width: %s" % nl80211.nl80211_chan_width2str[chanw])
				if nl80211.NL80211_ATTR_CENTER_FREQ1 in attr:
					sys.stdout.write(", center1: %d MHz" %
						nl.nla_get_u32(attr[nl80211.NL80211_ATTR_CENTER_FREQ1]))
				if nl80211.NL80211_ATTR_CENTER_FREQ2 in attr:
					sys.stdout.write(", center2: %d MHz" %
						nl.nla_get_u32(attr[nl80211.NL80211_ATTR_CENTER_FREQ2]))
			elif nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE in attr:
				channel_type = nl.nla_get_u32(attr[nl80211.NL80211_ATTR_WIPHY_CHANNEL_TYPE])
				sys.stdout.write(" %s" % nl80211.nl80211_channel_type2str(channel_type));

			sys.stdout.write("\n");
		return nl.NL_SKIP;
	except Exception as e:
		(t,v,tb) = sys.exc_info()
		print v.message
		traceback.print_tb(tb)
示例#15
0
def msg_handler(m, a):
	try:
		e, attr = genl.py_genlmsg_parse(nl.nlmsg_hdr(m), 0,
						nl80211.NL80211_ATTR_MAX, None)
		if nl80211.NL80211_ATTR_WIPHY_NAME in attr:
			print('wiphy %s' % nl.nla_get_string(attr[nl80211.NL80211_ATTR_WIPHY_NAME]))
		if nl80211.NL80211_ATTR_WIPHY_BANDS in attr:
			fpol = nl.nla_policy_array(nl80211.NL80211_FREQUENCY_ATTR_MAX + 1)
			fpol[nl80211.NL80211_FREQUENCY_ATTR_FREQ].type = nl.NLA_U32
			fpol[nl80211.NL80211_FREQUENCY_ATTR_DISABLED].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_PASSIVE_SCAN].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_NO_IBSS].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_RADAR].type = nl.NLA_FLAG
			fpol[nl80211.NL80211_FREQUENCY_ATTR_MAX_TX_POWER].type = nl.NLA_U32

			nattrs = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_WIPHY_BANDS])
			for nattr in nattrs:
				handle_band(nattr, fpol)
		if nl80211.NL80211_ATTR_CIPHER_SUITES in attr:
			ciphers = nl.nla_data(attr[nl80211.NL80211_ATTR_CIPHER_SUITES])
			num = len(ciphers) / 4
			if num > 0:
				print("\tSupported Ciphers:");
				for i in range(0, num, 4):
					print("\t\t* %s" % cipher_name(ciphers[i:i+4]))
		if nl80211.NL80211_ATTR_SUPPORTED_IFTYPES in attr:
			print("\tSupported interface modes:")
			ifattr = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_SUPPORTED_IFTYPES])
			for nl_mode in ifattr:
				print("\t\t* %s" % nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
		if nl80211.NL80211_ATTR_SOFTWARE_IFTYPES in attr:
			print("\tsoftware interface modes (can always be added):")
			ifattr = nl.nla_get_nested(attr[nl80211.NL80211_ATTR_SOFTWARE_IFTYPES])
			for nl_mode in ifattr:
				print("\t\t* %s" % nl80211.nl80211_iftype2str[nl.nla_type(nl_mode)])
		return nl.NL_SKIP
	except Exception as e:
		(t,v,tb) = sys.exc_info()
		print v.message
		traceback.print_tb(tb)
示例#16
0
    def handle(self, m):

        logger.debug("Handle Msg from class")
        print("m", m)
        try:
            logger.debug("getting msg header")
            nlmsghdr = nl.nlmsg_hdr(m)
            # print("nlmsghdr: flags:", nlmsghdr.nlmsg_flags , "seq:", nlmsghdr.nlmsg_seq )
            logger.debug("getting genlmsg header")
            genlhdr = genl.genlmsg_hdr(nlmsghdr)

            # logger.debug("Generic Command", genlhdr.cmd)

            if not genlhdr:
                logger.error("Could not get generic header")
                return nl.NL_STOP

            if genlhdr.cmd == ELC_REQUEST_RLOCS_FOR_EID:
                logger.info("Request RLOC for an EID")

                # attrs = None
                # print("Message handler got called");
                err, attrs = genl.py_genlmsg_parse(
                    nlmsghdr,
                    0,  # will be returned as an attribute
                    ELA_MAX,
                    None)

                if err < 0:
                    logger.error("An error happened while parsing attributes")
                    return nl.NL_STOP

                logger.info("Looking for ELA")
                if ELA_EID in attrs:
                    # logger.debug ("hello", attrs[ELA_EID])
                    eid = nl.nla_get_u32(attrs[ELA_EID])
                    # logger.info ("eid", eid)

                    # logger.debug ("token", attrs[ELA_MPTCP_TOKEN])
                    token = nl.nla_get_u32(attrs[ELA_MPTCP_TOKEN])
                    # logger.info("token", token)

                    # print("Requested EID ",eid, " for token ",binascii.hexlify( token ))

                    # I => unsigned int
                    packed_value = struct.pack('I', eid)
                    addr = socket.inet_ntoa(packed_value)

                    nb = self.retrieve_number_of_rlocs(addr)
                    if nb < 0:
                        logger.warning(
                            "An error happened while retrieveing nb of rlocs")
                        return nl.NL_STOP
                    else:
                        #nlmsghdr.nlmsg_seq + 1
                        self.send_rlocs_list_for_eid(0, token, nb)
                        return nl.NL_SKIP

                else:
                    logger.error("Missing critical attribute in packet")

            else:
                logger.warning("Unhandled command %d" % genlhdr.cmd)

            # nlmsg_data returns void* so not usable straightaway

            # TODO need to retrieve command
            # print("e", err)

            return nl.NL_SKIP

        except Exception as e:
            (t, v, tb) = sys.exc_info()
            print("test", v.message, e)
            traceback.print_tb(tb)

            return nl.NL_SKIP
示例#17
0
	def handle(self, m):


		logger.debug("Handle Msg from class")
		print("m",m)
		try:
			logger.debug("getting msg header")
			nlmsghdr = nl.nlmsg_hdr(m)
			# print("nlmsghdr: flags:", nlmsghdr.nlmsg_flags , "seq:", nlmsghdr.nlmsg_seq )
			logger.debug("getting genlmsg header")
			genlhdr = genl.genlmsg_hdr( nlmsghdr )

			# logger.debug("Generic Command", genlhdr.cmd)

			if not genlhdr:
				logger.error("Could not get generic header")
				return nl.NL_STOP


			if genlhdr.cmd == ELC_REQUEST_RLOCS_FOR_EID:
				logger.info("Request RLOC for an EID")

				
				# attrs = None
				# print("Message handler got called");
				err, attrs = genl.py_genlmsg_parse(
						nlmsghdr, 
						0, # will be returned as an attribute
		 				ELA_MAX, 
		 				None
		 				)

				if err < 0:
					logger.error("An error happened while parsing attributes")
					return nl.NL_STOP;


				logger.info("Looking for ELA")
				if ELA_EID in attrs:
					# logger.debug ("hello", attrs[ELA_EID])
					eid 	= nl.nla_get_u32(attrs[ELA_EID]);
					# logger.info ("eid", eid)

					# logger.debug ("token", attrs[ELA_MPTCP_TOKEN])
					token 	= nl.nla_get_u32(attrs[ELA_MPTCP_TOKEN]);
					# logger.info("token", token)

					# print("Requested EID ",eid, " for token ",binascii.hexlify( token ))

					# I => unsigned int
					packed_value = struct.pack('I', eid)
					addr = socket.inet_ntoa(packed_value)

					nb = self.retrieve_number_of_rlocs( addr )
					if nb < 0:
						logger.warning("An error happened while retrieveing nb of rlocs")
						return nl.NL_STOP
					else:
						#nlmsghdr.nlmsg_seq + 1
						self.send_rlocs_list_for_eid(  0, token, nb )
						return nl.NL_SKIP

				else:
					logger.error("Missing critical attribute in packet")

			else:
				logger.warning("Unhandled command %d"% genlhdr.cmd)

			# nlmsg_data returns void* so not usable straightaway

			# TODO need to retrieve command
			# print("e", err)

			return nl.NL_SKIP

		except Exception as e:
			(t,v,tb) = sys.exc_info()
			print( "test", v.message,e )
			traceback.print_tb(tb)

			return nl.NL_SKIP