def start(self): """ Start the softAP :param self: An AccessPoint object :type self: AccessPoint :return: None :rtype: None """ # create the configuration for roguehostapd hostapd_config = { "ssid": self.essid, "interface": self.interface, "channel": self.channel, "karma_enable": 1 } if self.psk: hostapd_config['wpa_passphrase'] = self.psk # create the option dictionary hostapd_options = { 'debug_level': hostapd_constants.HOSTAPD_DEBUG_OFF, 'mute': True, "eloop_term_disable": True } try: self.hostapd_object = hostapd_controller.Hostapd() self.hostapd_object.start(hostapd_config, hostapd_options) except KeyboardInterrupt: raise Exception # when roguehostapd fail to start rollback to use the hostapd # on the system except BaseException: hostapd_config.pop("karma_enable", None) hostapd_options = {} hostapd_config_obj = hostapd_controller.HostapdConfig() hostapd_config_obj.write_configs(hostapd_config, hostapd_options) self.update_black_macs() # handle exception if hostapd is not installed in system try: self.hostapd_object = subprocess.Popen( ['hostapd', hostapd_constants.HOSTAPD_CONF_PATH], stdout=constants.DN, stderr=constants.DN) except OSError: print("[" + constants.R + "!" + constants.W + "] " + "hostapd is not installed!") # just raise exception when hostapd is not installed raise Exception time.sleep(2) if self.hostapd_object.poll() is not None: print("[" + constants.R + "!" + constants.W + "] " + "hostapd failed to lunch!") raise Exception
def get_configuration_dicts(arg_dict): """ Get the dictionary for hostapd.conf and cmd line options """ config_obj = hostapd_controller.HostapdConfig() hostapd_dict = {} options = {} for key, val in arg_dict.iteritems(): if key in config_obj.configuration_dict: hostapd_dict[key] = val elif key in config_obj.options: options[key] = val return hostapd_dict, options