def get_interface_info(self, ifaceName): if not self._check_if_my_iface(ifaceName): self.log.error('check_if_my_iface failed') raise exceptions.FunctionExecutionFailed( func_name=inspect.currentframe().f_code.co_name, err_msg='No such interface: ' + ifaceName) dinfo = pyw.devinfo(ifaceName) # Delete card object from dict dinfo.pop("card", None) return dinfo
def get_phy_info(self, ifaceName): if not self._check_if_my_iface(ifaceName): self.log.error('check_if_my_iface failed') raise exceptions.FunctionExecutionFailed( func_name=inspect.currentframe().f_code.co_name, err_msg='No such interface: ' + ifaceName) dinfo = pyw.devinfo(ifaceName) card = dinfo['card'] pinfo = pyw.phyinfo(card) return pinfo
def get_wifi_chard(self, iface): ''' Get WiFi chard ''' if not self._check_if_my_iface(iface): self.log.error('check_if_my_iface failed') raise exceptions.FunctionExecutionFailed( func_name=inspect.currentframe().f_code.co_name, err_msg='No such interface: ' + iface) return pyw.getcard(iface) # get a card for interface
def set_tx_power(self, power_dBm, ifaceName): """ Sets TX power for that interface :param power_dBm: the power in dBm :param ifaceName: name of interface :return: True in case it was successful """ self.log.info('Setting power on iface {}:{} to {}'.format( ifaceName, self.device, str(power_dBm))) try: w0 = self.get_wifi_chard(ifaceName) # get a card for interface pyw.txset(w0, 'fixed', power_dBm) self.power = power_dBm except Exception as e: raise exceptions.FunctionExecutionFailed( func_name=inspect.currentframe().f_code.co_name, err_msg='Failed to set tx power: ' + str(e)) return True
def set_channel(self, channel, ifaceName, chw=None, **kwargs): """ Set the Rf channel :param channel: the new channel, i.e. channel number according to IEEE 802.11 spec :param ifaceName: name of the interface :param chw: bandwidth of the channel :param kwargs: optional args, i.e. path to control socket, :return: True in case it was successful """ self.log.info('Setting channel for {}:{} to {}'.format( ifaceName, self.device, channel)) try: w0 = self.get_wifi_chard(ifaceName) # get a card for interface # check mode dinfo = pyw.devinfo(w0) if dinfo['mode'] == 'AP': if not "control_socket_path" in kwargs: self.log.warn( 'Please pass the path to hostapd control socket') return False # pass new chanel to hostapd # hostapd requires frequency not channel freq = ch2rf(channel) control_socket_path = kwargs["control_socket_path"] beacon_periods = 5 cmd = ('sudo hostapd_cli -p {} chan_switch {} {}'.format( control_socket_path, beacon_periods, freq)) self.run_command(cmd) else: # chw: channel width oneof {None|'HT20'|'HT40-'|'HT40+'} # chw = None pyw.chset(w0, channel, chw) self.channel = channel except Exception as e: fname = inspect.currentframe().f_code.co_name self.log.fatal("An error occurred in %s: %s" % (fname, e)) raise exceptions.FunctionExecutionFailed(func_name=fname, err_msg=str(e)) return True