Description
The BlueZ D-Bus API introduced a new concept called adapter visibility. It is basically an abstraction for page/inquiry scan activity setup. The objective is improve the security(since incoming connections and inquiry responses can be blocked) and reduce the power consumption.
The following modes are available:
- off: page/inquiry scan disabled
- connectable: page scan enabled
- discoverable: page/inquiry scan enabled
When a device wants to receive inquiry packets it enters the inquiry scan mode(following the inquiry hopping sequence). When a device wants to receive page packets it enters the page scan mode(enabling connection establishment).
Discoverable timeout
In addition to discoverable mode a timeout can be used to switch automatically the adapter to the connectable mode. Setting Zero for the discoverable timeout means that the adapter will not leave the discoverable mode. Setting to N (seconds) means that the adapter will be automatically switched to the connectable mode after the time expires.
Signals
When the visibility mode is changed a D-Bus signal(ModeChanged) is sent to notify all applications interested on this change.
Python examples
import dbus import dbus.glib import gobject def mode_changed_signal(mode): print 'Signal: ModeChanged(%s)' % (mode) bus = dbus.SystemBus(); bus.add_signal_receiver(mode_changed_signal, 'ModeChanged', 'org.bluez.Adapter', 'org.bluez', '/org/bluez/hci0') obj = bus.get_object('org.bluez', '/org/bluez/hci0') adapter = dbus.Interface(obj, 'org.bluez.Adapter') print 'Currrent mode: %s' % (adapter.GetMode()) print 'Currrent timeout: %s' % (adapter.GetDiscoverableTimeout()) adapter.SetMode('discoverable') adapter.SetDiscoverableTimeout(dbus.UInt32(10)) gobject.threads_init() dbus.glib.init_threads() main_loop = gobject.MainLoop() main_loop.run()
dbus-send examples
* Getting the current values: $dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.GetMode $dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.GetDiscoverableTimeout * Changing to discoverable mode and setting the timeout to 60 seconds $dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.SetMode string:discoverable $dbus-send --system --type=method_call --print-reply --dest=org.bluez /org/bluez/hci0 org.bluez.Adapter.SetDiscoverableTimeout uint32:60
