Esempio n. 1
0
    def GetParams(self, manager, proto):
        """
        Returns a dict of paramters for the given proto on the given manager.
        The keys will be the parameters names, and the values a tuple of (dbus
        type, default value, flags). If no default value is specified, the
        second item in the tuple will be None.
        """

        params = {}
        config = self.services[manager]["protos"][proto]

        for key, val in config.iteritems():
            if not key.startswith('param-'):
                continue

            name = key[len('param-'):]
            values = val.split()
            type = values[0]
            flags = 0
            default = None

            if "register" in values:
                flags |= telepathy.CONN_MGR_PARAM_FLAG_REGISTER

            if "required" in values:
                flags |= telepathy.CONN_MGR_PARAM_FLAG_REQUIRED

            for key, val in config.iteritems():
                if key.strip().startswith("default-" + name):
                    if _dbus_py_version < (0, 80):
                        default = dbus.Variant(val.strip(), signature=type)
                    else:
                        default = val.strip()
                        if type in 'uiqntxy':
                            default = int(default)
                        elif type == 'b':
                            if default.lower() in ('0', 'false'):
                                default = False
                            else:
                                default = True
                        elif type == 'd':
                            default = float(default)
                        # we don't support non-basic types
                    flags |= telepathy.CONN_MGR_PARAM_FLAG_HAS_DEFAULT

            params[name] = (type, default, flags)

        return params
Esempio n. 2
0
def main():
	if len(sys.argv) != 2:
		print "Usage: wpas-test.py <interface>"
		os._exit(1)

	ifname = sys.argv[1]

	bus = dbus.SystemBus()
	wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
	wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)

	# See if wpa_supplicant already knows about this interface
	path = None
	try:
		path = wpas.getInterface(ifname)
	except dbus.dbus_bindings.DBusException, exc:
		if str(exc) != "wpa_supplicant knows nothing about this interface.":
			raise exc
		try:
			path = wpas.addInterface(ifname, {'driver': dbus.Variant('wext')})
		except dbus.dbus_bindings.DBusException, exc:
			if str(exc) != "wpa_supplicant already controls this interface.":
				raise exc
Esempio n. 3
0
def main():
	if len(sys.argv) != 2:
		print("Usage: wpas-test.py <interface>")
		os._exit(1)

	ifname = sys.argv[1]

	bus = dbus.SystemBus()
	wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
	wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)

	# See if wpa_supplicant already knows about this interface
	path = None
	try:
		path = wpas.getInterface(ifname)
	except dbus.dbus_bindings.DBusException as exc:
		if str(exc) != "wpa_supplicant knows nothing about this interface.":
			raise exc
		try:
			path = wpas.addInterface(ifname, {'driver': dbus.Variant('wext')})
		except dbus.dbus_bindings.DBusException as exc:
			if str(exc) != "wpa_supplicant already controls this interface.":
				raise exc

	if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
	iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE)
	iface.scan()
	# Should really wait for the "scanResults" signal instead of sleeping
	time.sleep(5)
	res = iface.scanResults()

	print("Scanned wireless networks:")
	for opath in res:
		net_obj = bus.get_object(WPAS_DBUS_SERVICE, opath)
		net = dbus.Interface(net_obj, WPAS_DBUS_BSSID_INTERFACE)
		props = net.properties()

		# Convert the byte-array for SSID and BSSID to printable strings
		bssid = ""
		for item in props["bssid"]:
			bssid = bssid + ":%02x" % item
		bssid = bssid[1:]
		ssid = byte_array_to_string(props["ssid"])
		wpa = "no"
		if props.has_key("wpaie"):
			wpa = "yes"
		wpa2 = "no"
		if props.has_key("rsnie"):
			wpa2 = "yes"
		freq = 0
		if props.has_key("frequency"):
			freq = props["frequency"]
		caps = props["capabilities"]
		qual = props["quality"]
		level = props["level"]
		noise = props["noise"]
		maxrate = props["maxrate"] / 1000000

		print("  %s  ::  ssid='%s'  wpa=%s  wpa2=%s  quality=%d%%  rate=%d  freq=%d" % (bssid, ssid, wpa, wpa2, qual, maxrate, freq))

	wpas.removeInterface(dbus.ObjectPath(path))
	# Should fail here with unknown interface error
	iface.scan()