Example #1
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)
Example #2
0
    def store_attrs(self, attrs):
        for aid in attrs.keys():
            try:
                pol = self._policy[aid]
                if pol.type == NLA_S8:
                    pol.type = nl.NLA_U8
                    pol.signed = True
                elif pol.type == NLA_S16:
                    pol.type = nl.NLA_U16
                    pol.signed = True
                elif pol.type == NLA_S32:
                    pol.type = nl.NLA_U32
                    pol.signed = True
                elif pol.type == NLA_S64:
                    pol.type = nl.NLA_U64
                    pol.signed = True

                if pol.type == NLA_NUL_STRING:
                    self._attrs[aid] = nl.nla_get_string(attrs[aid])
                elif pol.type == nl.NLA_U64:
                    self._attrs[aid] = nl.nla_get_u64(attrs[aid])
                elif pol.type == nl.NLA_U32:
                    self._attrs[aid] = nl.nla_get_u32(attrs[aid])
                elif pol.type == nl.NLA_U16:
                    self._attrs[aid] = nl.nla_get_u16(attrs[aid])
                elif pol.type == nl.NLA_U8:
                    self._attrs[aid] = nl.nla_get_u8(attrs[aid])
                elif pol.type == nl.NLA_FLAG:
                    self._attrs[aid] = True
                elif pol.type == nl.NLA_NESTED:
                    if hasattr(pol, 'single') and pol.single:
                        obj = self.create_nested(attrs[aid], aid)
                    elif hasattr(pol, 'map') and pol.map:
                        if not hasattr(pol, 'list_type'):
                            raise Exception(
                                'need to specify "list_type" for map')
                        obj = self.create_map(attrs[aid], pol)
                    elif hasattr(pol, 'list_type'):
                        obj = self.create_list(attrs[aid], pol)
                    else:
                        obj = self.create_nested_list(attrs[aid], aid)
                    self.merge_nested_attrs(aid, obj)
                elif pol.type in [NLA_BINARY, nl.NLA_UNSPEC]:
                    self._attrs[aid] = nl.nla_data(attrs[aid])
                if hasattr(pol, 'signed') and pol.signed:
                    self._attrs[aid] = self.convert_sign(self._attrs[aid], pol)
            except Exception as e:
                print e.message
                self._attrs[aid] = nl.nla_data(attrs[aid])
        self.post_store_attrs(attrs)
Example #3
0
	def store_attrs(self, attrs):
		for aid in attrs.keys():
			try:
				pol = self._policy[aid]
				if pol.type == NLA_S8:
					pol.type = NLA_U8
					pol.signed = True
				elif pol.type == NLA_S16:
					pol.type = NLA_U16
					pol.signed = True
				elif pol.type == NLA_S32:
					pol.type = NLA_U32
					pol.signed = True
				elif pol.type == NLA_S64:
					pol.type = NLA_U64
					pol.signed = True

				if pol.type == NLA_NUL_STRING:
					self._attrs[aid] = nla_get_string(attrs[aid])
				elif pol.type == NLA_U64:
					self._attrs[aid] = nla_get_u64(attrs[aid])
				elif pol.type == NLA_U32:
					self._attrs[aid] = nla_get_u32(attrs[aid])
				elif pol.type == NLA_U16:
					self._attrs[aid] = nla_get_u16(attrs[aid])
				elif pol.type == NLA_U8:
					self._attrs[aid] = nla_get_u8(attrs[aid])
				elif pol.type == NLA_FLAG:
					self._attrs[aid] = True
				elif pol.type == NLA_NESTED:
					if hasattr(pol, 'single') and pol.single:
						obj = self.create_nested(attrs[aid], aid)
					elif hasattr(pol, 'map') and pol.map:
						if not hasattr(pol, 'list_type'):
							raise Exception('need to specify "list_type" for map')
						obj = self.create_map(attrs[aid], pol)
					elif hasattr(pol, 'list_type'):
						obj = self.create_list(attrs[aid], pol)
					else:
						obj = self.create_nested_list(attrs[aid], aid)
					self.merge_nested_attrs(aid, obj)
				elif pol.type in [ NLA_BINARY, NLA_UNSPEC ]:
					self._attrs[aid] = nla_data(attrs[aid])
				if hasattr(pol, 'signed') and pol.signed:
					self._attrs[aid] = self.convert_sign(self._attrs[aid], pol)
			except Exception as e:
				print e.message
				self._attrs[aid] = nla_data(attrs[aid])
		self.post_store_attrs(attrs)
Example #4
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)
Example #5
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)
Example #6
0
 def create_list(self, attr_list, pol):
     nest_list = []
     item_type = pol.list_type
     for item in nl.nla_get_nested(attr_list):
         if item_type == NLA_NUL_STRING:
             nest_obj = nl.nla_get_string(item)
         elif item_type == nl.NLA_U64:
             nest_obj = nl.nla_get_u64(item)
         elif item_type == nl.NLA_U32:
             nest_obj = nl.nla_get_u32(item)
         elif item_type == nl.NLA_U16:
             nest_obj = nl.nla_get_u16(item)
         elif item_type == nl.NLA_U8:
             nest_obj = nl.nla_get_u8(item)
         else:
             raise Exception("type (%d) not supported for list" % item_type)
         nest_list.append(nest_obj)
     return nest_list
Example #7
0
	def create_list(self, attr_list, pol):
		nest_list = []
		item_type = pol.list_type
		for item in nla_get_nested(attr_list):
			if item_type == NLA_NUL_STRING:
				nest_obj = nla_get_string(item)
			elif item_type == NLA_U64:
				nest_obj = nla_get_u64(item)
			elif item_type == NLA_U32:
				nest_obj = nla_get_u32(item)
			elif item_type == NLA_U16:
				nest_obj = nla_get_u16(item)
			elif item_type == NLA_U8:
				nest_obj = nla_get_u8(item)
			else:
				raise Exception("type (%d) not supported for list" % item_type)
			nest_list.append(nest_obj)
		return nest_list
Example #8
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)
Example #9
0
	def store_attrs(self, attrs):
		for attr in attrs.keys():
			try:
				pol = self._policy[attr]
				if pol.type == NLA_NUL_STRING:
					self._attrs[attr] = nl.nla_get_string(attrs[attr])
				elif pol.type == nl.NLA_U64:
					self._attrs[attr] = nl.nla_get_u64(attrs[attr])
				elif pol.type == nl.NLA_U32:
					self._attrs[attr] = nl.nla_get_u32(attrs[attr])
				elif pol.type == nl.NLA_U16:
					self._attrs[attr] = nl.nla_get_u16(attrs[attr])
				elif pol.type == nl.NLA_U8:
					self._attrs[attr] = nl.nla_get_u8(attrs[attr])
				elif pol.type == nl.NLA_FLAG:
					self._attrs[attr] = True
				elif pol.type == nl.NLA_NESTED:
					self.store_nested(attrs[attr], attr)
				elif pol.type in [ NLA_BINARY, nl.NLA_UNSPEC ]:
					self._attrs[attr] = nl.nla_data(attrs[attr])
			except Exception as e:
				print e.message
				self._attrs[attr] = nl.nla_data(attrs[attr])
Example #10
0
 def store_attrs(self, attrs):
     for attr in attrs.keys():
         try:
             pol = self._policy[attr]
             if pol.type == NLA_NUL_STRING:
                 self._attrs[attr] = nl.nla_get_string(attrs[attr])
             elif pol.type == nl.NLA_U64:
                 self._attrs[attr] = nl.nla_get_u64(attrs[attr])
             elif pol.type == nl.NLA_U32:
                 self._attrs[attr] = nl.nla_get_u32(attrs[attr])
             elif pol.type == nl.NLA_U16:
                 self._attrs[attr] = nl.nla_get_u16(attrs[attr])
             elif pol.type == nl.NLA_U8:
                 self._attrs[attr] = nl.nla_get_u8(attrs[attr])
             elif pol.type == nl.NLA_FLAG:
                 self._attrs[attr] = True
             elif pol.type == nl.NLA_NESTED:
                 self.store_nested(attrs[attr], attr)
             elif pol.type in [NLA_BINARY, nl.NLA_UNSPEC]:
                 self._attrs[attr] = nl.nla_data(attrs[attr])
         except Exception as e:
             print e.message
             self._attrs[attr] = nl.nla_data(attrs[attr])
Example #11
0
	def __init__(self, access, attrs):
		nl80211_managed_object.__init__(self, access, attrs, nl80211_policy)
		self._wdevid = nl.nla_get_u64(attrs[nl80211.ATTR_WDEV])
Example #12
0
 def __init__(self, access, attrs):
     nl80211_managed_object.__init__(self, access, attrs, nl80211_policy)
     self._wdevid = nla_get_u64(attrs[nl80211.ATTR_WDEV])