def create_map(self, map_attr, pol): nest_map = {} for key in nla_get_nested(map_attr): nest_list = self.create_list(key, pol) if len(nest_list) > 0: nest_map[nla_type(key)] = nest_list return nest_map
def handle_band(attr, fpol): e, battr = nl.py_nla_parse_nested(nl80211.NL80211_BAND_ATTR_MAX, attr, None) print("\tband %d:" % nl.nla_type(attr)) if nl80211.NL80211_BAND_ATTR_FREQS in battr: for fattr in nl.nla_get_nested(battr[nl80211.NL80211_BAND_ATTR_FREQS]): handle_freq(fattr, fpol)
def create_map(self, map_attr, pol): nest_map = {} for key in nl.nla_get_nested(map_attr): nest_list = self.create_list(key, pol) if len(nest_list) > 0: nest_map[nl.nla_type(key)] = nest_list return nest_map
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)
def create_nested_list(self, attr_list, aid): nest_list = [] for nest_element in nl.nla_get_nested(attr_list): nest_obj = self.create_nested(nest_element, aid) if isinstance(nest_obj, nl80211_object): nest_obj.nla_type = nl.nla_type(nest_element) nest_list.append(nest_obj) return nest_list
def create_nested(self, attr, aid): try: if aid in self.nest_attr_map.keys(): (nest_class, max_nest, nest_policy) = self.nest_attr_map[aid] e, nattr = nl.py_nla_parse_nested(max_nest, attr, nest_policy) return factory.get_inst().create(nest_class, nattr, nest_policy) except Exception as e: return nl.nla_type(attr)
def create_nested_list(self, attr_list, aid): nest_list = [] for nest_element in nla_get_nested(attr_list): nest_obj = self.create_nested(nest_element, aid) if isinstance(nest_obj, nl80211_object): nest_obj.nla_type = nla_type(nest_element) nest_list.append(nest_obj) return nest_list
def create_nested(self, attr, aid): try: if aid in self.nest_attr_map.keys(): (nest_class, max_nest, nest_policy) = self.nest_attr_map[aid] e, nattr = py_nla_parse_nested(max_nest, attr, nest_policy) return factory.get_inst().create(nest_class, nattr, nest_policy) except Exception as e: return nla_type(attr)
def store_nested(self, attr, aid): nest_class = None if aid in self.nest_attr_map.keys(): nest_class = self.nest_attr_map[aid] self._attrs[aid] = [] for nest_element in nl.nla_get_nested(attr): if nest_class == None: self._attrs[aid].append(nl.nla_type(nest_element)) else: e, nattr = nl.py_nla_parse_nested(nest_class.max_attr, nest_element, nest_class.policy) self._attrs[aid].append(nest_class(nattr))
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)