Exemple #1
0
 def disconnect(self):
     """Disconnect from current SSID"""
     status = self.get_connection_info()
     nid = status.get("id")
     if nid:
         ssid = status.get("ssid")
         wpa(self.wiface, 'disable', nid)
         LOG.info("Disconnecting %s id: %s" % (ssid, nid))
    def __init__(self, wiface):
        self.wiface = wiface
        self.subnet = '172.24.1'
        self.ip = self.subnet + '.1'
        self.ip_start = self.subnet + '.50'
        self.ip_end = self.subnet + '.150'

        wpa(self.wiface, 'p2p_group_add', 'persistent=0')
        self.iface = self.get_iface()
        self.password = wpa(self.iface, 'p2p_get_passphrase')

        LOG.debug('Wiface: ' + self.wiface)
        LOG.debug('Iface: ' + self.iface)

        card = pyw.getcard(self.iface)
        pyw.inetset(card, self.ip)
        copyfile('/etc/dnsmasq.conf', '/tmp/dnsmasq-bk.conf')
        self.save()
        sysctrl('restart', 'dnsmasq.service')
 def close(self):
     sysctrl('stop', 'dnsmasq.service')
     sysctrl('disable', 'dnsmasq.service')
     wpa(self.wiface, 'p2p_group_remove', self.iface)
     copyfile('/tmp/dnsmasq-bk.conf', '/etc/dnsmasq.conf')
Exemple #4
0
    def connect(self, ssid, password=None):
        LOG.info('Connecting to ' + ssid + '...')
        connected = self.is_connected(ssid)

        if connected:
            LOG.warning("Device is already connected to %s" % ssid)
        else:
            self.disconnect()
            LOG.info("Connecting to: %s" % ssid)
            nid = wpa(self.wiface, 'add_network')
            wpa(self.wiface, 'set_network', nid, 'ssid', '"' + ssid + '"')

            if password:
                psk = '"' + password + '"'
                wpa(self.wiface, 'set_network', nid, 'psk', psk)
            else:
                wpa(self.wiface, 'set_network', nid, 'key_mgmt', 'NONE')

            wpa(self.wiface, 'enable', nid)
            connected = self.get_connected(ssid)
            if connected:
                wpa(self.wiface, 'save_config')

        trigger_event(
            'ap_connection_success' if connected else 'ap_connection_failed')
        self.notify_server('connection.status', {'connected': connected})
        LOG.info("Connection status for %s = %s" % (ssid, connected))