Beispiel #1
0
    def __init__(self, config):
        Network.__init__(self)
        self.config = config
        import pyconnman
        import dbus
        self.dbus = dbus
        self.p = pyconnman
        try:
            self.manager = pyconnman.ConnManager()
        except self.dbus.exceptions.DBusException as e:
            logging.warning("Connman not a known service on DBus")
            return
        self.technologies = self.manager.get_technologies()
        self.wifi = None
        self.ethernet = None
        self.bluetooth = None
        self.aps_by_path = {}

        for t in self.technologies:
            (path, params) = t
            if params['Name'] == "WiFi":
                self.wifi = pyconnman.ConnTechnology(path)
                self._start_agent()
            elif params['Name'] == "Wired":
                self.ethernet = pyconnman.ConnTechnology(path)
            elif params['Name'] == "Bluetooth":
                self.bluetooth = t
        self.manager.add_signal_receiver(self.services_changed,
                                         self.manager.SIGNAL_SERVICES_CHANGED,
                                         None)
        if self.wifi:
            self.wifi.add_signal_receiver(self.wifi_changed,
                                          self.wifi.SIGNAL_PROPERTY_CHANGED,
                                          None)
        def list():
            self.bScanning = True
            tech = pyconnman.ConnTechnology('/net/connman/technology/wifi')
            while self.bScanning:
                try:
                    tech.scan()
                    print("scan")
                    self.bScanning = False
                    break

                except:
                    # The carrier might not be ready yet if wifi is still powering on
                    time.sleep(1)
                    print("sleep")

            self.services = self.manager.get_services()
            self.getConnectedSSID()
            wifiList = {}

            for (path, params) in self.services:
                try:
                    wifiList[path] = {}
                    wifiList[path]['ssid'] = str(dbus.String(params['Name']))
                    wifiList[path]['security'] = str(
                        dbus.String(params['Security'][0]))
                    wifiList[path]['strength'] = int(
                        dbus.Byte(params['Strength']))
                    wifiList[path]['online'] = (
                        self.connectedSSID == wifiList[path]['ssid'])
                except:
                    pass

            dispatcher.send(signal="wifi_scan_complete", data=wifiList)
            self.bScanning = False
Beispiel #3
0
def wifi_connected():
    try:
        if (not wifi_enabled()):
            return False
        tech = pyconnman.ConnTechnology(CONNCTRL_TECH_PATH_WIFI)
        return tech.get_property('Connected')
    except Exception, e:
        print e
        return False
Beispiel #4
0
def tech_disable(path):
    try:
        if (not tech_enabled(path)):
            return True
        tech = pyconnman.ConnTechnology(path)
        tech.set_property('Powered', False)
        return True
    except Exception, e:
        print e
        return False
Beispiel #5
0
def technology_scan(args):
    if (len(args)):
        tech_path = args.pop(0)
    else:
        print('Error: Must specify technology path')
        return

    try:
        tech = pyconnman.ConnTechnology(tech_path)
        tech.scan()
    except dbus.exceptions.DBusException:
        print('Unable to complete:', sys.exc_info())
Beispiel #6
0
def technology_set(args):
    if (len(args) >= 3):
        tech_path = args.pop(0)
        name = args.pop(0)
        value = args.pop(0)
    else:
        print('Error: Requires technology path, property name and value')
        return

    try:
        tech = pyconnman.ConnTechnology(tech_path)
        tech.set_property(name, value)
    except dbus.exceptions.DBusException:
        print('Unable to complete:', sys.exc_info())
Beispiel #7
0
def technology_info(args):
    if (len(args)):
        tech_path = args.pop(0)
    else:
        print 'Error: Must specify technology path'
        return

    try:
        tech = pyconnman.ConnTechnology(tech_path)
        print '========================================================='
        print tech
        print '========================================================='
    except dbus.exceptions.DBusException:
        print 'Unable to complete:', sys.exc_info()
Beispiel #8
0
def wifi_service_path(ssid):
    try:
        tech = pyconnman.ConnTechnology(CONNCTRL_TECH_PATH_WIFI)
        tech.scan()
        services = pyconnman.ConnManager().get_services()
        for i in services:
            (path, params) = i
            if (params['Type'] == 'wifi'):
                if (params['Name'] == ssid):
                    return path
        return None
    except Exception, e:
        print e
        return None
Beispiel #9
0
def technology_get(args):
    if (len(args)):
        tech_path = args.pop(0)
        if (len(args)):
            name = args.pop(0)
        else:
            name = None
    else:
        print('Error: Requires technology path')
        return

    try:
        tech = pyconnman.ConnTechnology(tech_path)
        print('=========================================================')
        print(tech.get_property(name=name))
    except dbus.exceptions.DBusException:
        print('Unable to complete:', sys.exc_info())
Beispiel #10
0
 def test_scan(self):
     manager = pyconnman.ConnManager()
     technologies = manager.get_technologies()
     tech = pyconnman.ConnTechnology(technologies[0][0])
     print repr(tech)
     print '========================================================='
     print tech
     print '========================================================='
     added = 'Added'
     removed = 'Removed'
     signal = pyconnman.ConnManager.SIGNAL_SERVICES_CHANGED
     user = mock.MagicMock()
     manager.add_signal_receiver(user.callback_fn, signal, self)
     tech.scan()
     self.mock_system_bus.add_signal_receiver.assert_called()
     cb = self.mock_system_bus.add_signal_receiver.call_args_list[0][0][0]
     cb(added, removed)
     user.callback_fn.assert_called_with(signal, self, added, removed)
     user.callback_fn.assert_called()
     manager.remove_signal_receiver(signal)
     self.mock_system_bus.remove_signal_receiver.assert_called()
Beispiel #11
0
def tech_enabled(path):
    tech = pyconnman.ConnTechnology(path)
    return tech.get_property('Powered')
Beispiel #12
0
        }

        print '* registering authentication agent'

        agent_path = '/resin/agent'

        agent = pyconnman.SimpleWifiAgent(agent_path)
        agent.set_service_params('*', params['name'], params['ssid'],
                                 params['identity'], params['username'],
                                 params['password'], params['passphrase'],
                                 params['wpspin'])

        manager.register_agent(agent_path)
        print '* auth agent has been registered'

        tech = pyconnman.ConnTechnology('/net/connman/technology/wifi')

        print '* clean iptables'
        subprocess.call(['/app/wifi/setup-iptables.sh', 'R'])

        tethering = tech.get_property('Tethering')
        print '* currently tethering? ', tethering

        if tethering:
            print '* disable tethering'
            tech.set_property('Tethering', False)

            # TODO: change this hardcoded sleep time
            print '* sleeping for 15s'
            time.sleep(15)
 def setWifiPower(self, bState):
     tech = pyconnman.ConnTechnology('/net/connman/technology/wifi')
     if tech.get_property('Powered') == 0 and bState == True:
         tech.set_property('Powered', 1)
     elif tech.get_property('Powered') == 1 and bState == False:
         tech.set_property('Powered', 0)