Beispiel #1
0
    def _connect(self):
        # Activate existing connection, if there is one
        connection = network.find_connection_by_ssid(self._ssid)
        if connection:
            logging.debug('Activating existing connection for SSID %r',
                          self._ssid)
            connection.activate(self._device)
            return

        # Otherwise, create new connection and activate it
        logging.debug('Creating new connection for SSID %r', self._ssid)
        settings = Settings()
        settings.connection.id = self._display_name
        settings.connection.uuid = str(uuid.uuid4())
        settings.connection.type = '802-11-wireless'
        settings.wireless.ssid = self._ssid

        if self._mode == network.NM_802_11_MODE_INFRA:
            settings.wireless.mode = 'infrastructure'
            settings.connection.autoconnect = True
        elif self._mode == network.NM_802_11_MODE_ADHOC:
            settings.wireless.mode = 'adhoc'
            settings.wireless.band = 'bg'
            settings.ip4_config = IP4Config()
            settings.ip4_config.method = 'link-local'

        wireless_security = self._get_security()
        settings.wireless_security = wireless_security

        if wireless_security is not None:
            settings.wireless.security = '802-11-wireless-security'

        network.add_and_activate_connection(self._device, settings,
                                            self.get_first_ap().model)
Beispiel #2
0
 def _add_connection(self, channel):
     ssid = 'Ad-hoc Network %d' % (channel, )
     settings = Settings()
     settings.connection.id = self._get_connection_id(channel)
     settings.connection.uuid = str(uuid.uuid4())
     settings.connection.type = '802-11-wireless'
     settings.connection.autoconnect = False
     settings.wireless.ssid = dbus.ByteArray(ssid)
     settings.wireless.band = 'bg'
     settings.wireless.channel = channel
     settings.wireless.mode = 'adhoc'
     settings.ip4_config = IP4Config()
     settings.ip4_config.method = 'link-local'
     network.add_connection(settings)