linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Registering profile or making discoverable resets adapter class
@ 2016-08-01 12:34 Serge van den Boom
  2016-08-01 14:13 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 5+ messages in thread
From: Serge van den Boom @ 2016-08-01 12:34 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

When a new profile is registered, or an adapter is make discoverable,
the device class of the adapter is reset to the value set in
/etc/bluetooth/main.conf.

The test case below (to be run as root) demonstrates the issue. For this
demonstration, there should be no 'Class = ...' setting in
/etc/bluetooth/main.conf.


Regards,

Serge van den Boom


Output:
============================================================================
Registering signal receiver for property changes.
Starting main loop.
Making adapter '/org/bluez/hci0' non-discoverable.
Setting the Bluetooth device class to 0x000540 through hciconfig.
Class changed to 0x000540.
Registering profile.
Class changed to 0x100000.
Setting the Bluetooth device class to 0x000540 through hciconfig.
Class changed to 0x000540.
Making adapter '/org/bluez/hci0' discoverable.
Class changed to 0x100000.
Exiting.
============================================================================


The test case:
============================================================================
#!/usr/bin/env python3
import dbus.mainloop.glib
import logging
import subprocess
import time
from gi.repository import GLib
	
logging.basicConfig(format="%(message)s", level=logging.INFO)

DEVICE_CLASS = 0x000540
IFACE = "hci0"
ADAPTER = "/org/bluez/hci0"

def classChanged(interface, changed, invalidated):
	if 'Class' in changed:
		logging.info("Class changed to 0x{:06x}.".format(changed['Class']))

def step():
	logging.info("Making adapter '{}' non-discoverable.".format(ADAPTER))
	adapterProps = dbus.Interface(
			bus.get_object('org.bluez', ADAPTER), dbus.PROPERTIES_IFACE)
	adapterProps.Set('org.bluez.Adapter1', 'Discoverable', False)
	yield True

	logging.info("Setting the Bluetooth device class to 0x{:06x} through "
			"hciconfig.".format(DEVICE_CLASS))
	subprocess.call(["hciconfig", IFACE, "class", "0x{:06x}".format(DEVICE_CLASS)])
	yield True

	logging.info("Registering profile.".format(ADAPTER))
	profileManager = dbus.Interface(bus.get_object("org.bluez", "/org/bluez"),
			"org.bluez.ProfileManager1")
	profileManager.RegisterProfile("/org/example/test/profile",
			"00001124-0000-1000-8000-00805f9b34fb", {})
	yield True

	logging.info("Setting the Bluetooth device class to 0x{:06x} through "
			"hciconfig.".format(DEVICE_CLASS))
	subprocess.call(["hciconfig", IFACE, "class", "0x{:06x}".format(DEVICE_CLASS)])
	yield True

	logging.info("Making adapter '{}' discoverable.".format(ADAPTER))
	adapterProps = dbus.Interface(
			bus.get_object('org.bluez', ADAPTER), dbus.PROPERTIES_IFACE)
	adapterProps.Set('org.bluez.Adapter1', 'Discoverable', True)
	yield True

	logging.info("Exiting.")
	gMainLoop.quit()
	yield False

# Prepare the main loop for D-Bus.
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SystemBus()

# Listen for changes to the adapter class.
logging.info("Registering signal receiver for property changes.")
bus.add_signal_receiver(classChanged, bus_name="org.bluez",
		dbus_interface="org.freedesktop.DBus.Properties", path=ADAPTER,
		signal_name="PropertiesChanged")

# Schedule a step every second.
stepGenerator = step()
GLib.timeout_add(1000, lambda: next(stepGenerator))

# Go!
logging.info("Starting main loop.".format(ADAPTER))
gMainLoop = GLib.MainLoop()
gMainLoop.run()
============================================================================


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2016-08-02  8:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-08-01 12:34 Registering profile or making discoverable resets adapter class Serge van den Boom
2016-08-01 14:13 ` Luiz Augusto von Dentz
2016-08-01 16:12   ` Serge van den Boom
2016-08-01 18:52     ` Luiz Augusto von Dentz
2016-08-02  8:53       ` Serge van den Boom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).