Skip to contentSkip to conversation

Cleaning up the D-Bus interface

Bluez-devel Marcel Holtmann 3 participants 14 messages Dec 20, 2005 – Feb 7, 2006 Bluetooth drivers

lore
Share & tools
lore

Marcel Holtmann

author maintainer
#0 lore raw

Hi guys,

I always said that the D-Bus interface won't have to be designed after any technical part of the Bluetooth specification and I think it is time to change the discoverable and connectable options.

The Bluetooth specification and most devices allow you to set the device to discoverable, but not connectable. The combination actually makes no sense at all, because for the name resolving the remote device must be connectable. I would propose to have a "mode" property with actually three different states: Off, Connectable, Discoverable/Connectable. The Off state also makes the Up/Down functions obsolete, because they are BlueZ internal and in some embedded devices you might wanna also have deep sleep mode support. The internals should be all hidden from the userspace and for desktop devices the Off option could mean inquiry and page scan disabled.

The other option that is needed is of course the device name. With the upcoming extended inquiry the question is now if we also wanna support a short name or if hcid/bluetoothd should shorten the name by itself if needed.

We also have to deal with the major and minor part of the device class. The other bits would be set by sdpd if a specific profile has been registered.

What else needs to be configurable?

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#1 lore raw

Hi Marcel,

I agree about the "mode" property. But about Up and Down we have to consider issues like security and power save. Will the Off mode (nopiscan) be equivalent to device Down in power consumption?

BR,
Eduardo.

Quoted 30 lines · Marcel Holtmann

Hi guys,

I always said that the D-Bus interface won't have to be designed after any technical part of the Bluetooth specification and I think it is time to change the discoverable and connectable options.

The Bluetooth specification and most devices allow you to set the device to discoverable, but not connectable. The combination actually makes no sense at all, because for the name resolving the remote device must be connectable. I would propose to have a "mode" property with actually three different states: Off, Connectable, Discoverable/Connectable. The Off state also makes the Up/Down functions obsolete, because they are BlueZ internal and in some embedded devices you might wanna also have deep sleep mode support. The internals should be all hidden from the userspace and for desktop devices the Off option could mean inquiry and page scan disabled.

The other option that is needed is of course the device name. With the upcoming extended inquiry the question is now if we also wanna support a short name or if hcid/bluetoothd should shorten the name by itself if needed.

We also have to deal with the major and minor part of the device class. The other bits would be set by sdpd if a specific profile has been registered.

What else needs to be configurable?

Regards

Quoted 7 lines

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=

les

Quoted 8 lines

for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

author maintainer
#2 lore raw

Hi Eduardo,

Quoted 3 lines

I agree about the "mode" property. But about Up and Down we have to consider issues like security and power save. Will the Off mode (nopiscan) be equivalent to device Down in power consumption?

this is implementation specific. On some embedded devices, this might be the same as deep-sleep. Others might disconnect the device from the bus or simply call down. The user interface shouldn't have to care about it.

I think that we also need something like a status which shows if the device is idle, running an inquiry or have active connections.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#3 lore raw

Hi Marcel,

any suggestion about Discoverable/Connectable parameter string? Maybe "Ful= l" ?

BR,
Eduardo.

Quoted 15 lines · Marcel Holtmann

Hi Eduardo,

Quoted 3 lines

I agree about the "mode" property. But about Up and Down we have to consider issues like security and power save. Will the Off mode (nopiscan) be equivalent to device Down in power consumption?

this is implementation specific. On some embedded devices, this might be the same as deep-sleep. Others might disconnect the device from the bus or simply call down. The user interface shouldn't have to care about it.

I think that we also need something like a status which shows if the device is idle, running an inquiry or have active connections.

Regards

Quoted 7 lines

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=

les

Quoted 8 lines

for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

author maintainer
#4 lore raw

Hi Eduardo,

Quoted 1 line

any suggestion about Discoverable/Connectable parameter string? Maybe "Full" ?

besides the property thing, I like to see something like:

	SetMode(uint8 mode)	[Method]
	uint8 GetMode()		[Method]
	ModeChanged(uint8)	[Signal]

	mode 0x00	= Off (means down or deep-sleep)
	mode 0x01	= Connectable
	mode 0x02	= Connectable and Discoverable

What do you thing?

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#5 lore raw

Hi Marcel,

do you mean have both implementations (SetProperty("mode") and SetMode) ?

BR,
Eduardo.

Quoted 3 lines · Marcel Holtmann

Hi Eduardo,

Quoted 1 line

any suggestion about Discoverable/Connectable parameter string? Maybe =

"Full" ?

Quoted 15 lines

besides the property thing, I like to see something like:

        SetMode(uint8 mode)     [Method]
        uint8 GetMode()         [Method]
        ModeChanged(uint8)      [Signal]
        mode 0x00       =3D Off (means down or deep-sleep)
        mode 0x01       =3D Connectable
        mode 0x02       =3D Connectable and Discoverable

What do you thing?

Regards

Quoted 7 lines

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log fi=

les

Quoted 8 lines

for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=3D7637&alloc_id=3D16865&op=3Dclick
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
Eduardo Rocha
Instituto Nokia de Tecnologia - INdT

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

author maintainer
#6 lore raw

Hi Eduardo,

Quoted 1 line

do you mean have both implementations (SetProperty("mode") and SetMode) ?

we can have both, but I would prefer the SetMode() stuff.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

author maintainer
#7 lore raw

Hi Eduardo,

Quoted 3 lines
Quoted 1 line

do you mean have both implementations (SetProperty("mode") and SetMode) ?

we can have both, but I would prefer the SetMode() stuff.

and if a device is in Connectable only mode it would be great if we have another method that makes this device discoverable for a specific time. For example make it discoverable for 3 minutes, like the early Ericsson phones did.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#8 lore raw

Hi guys,

This patch is based on your discussion, but there are some changes:
1. The scan enable values are based on the Bluetooth Spec in order to make the logic more clear:

mode 0x00       = Off (means down or deep-sleep)
mode 0x01       = Discoverable (NOT ALLOWED)
mode 0x02       = Connectable
mode 0x03       = Connectable and Discoverable

2. SetProperty/GetProperty can be used to set/get scan value According with the previous discussion, we can have both, but SetMode/GetMode is the preferred approach. This patch support only SetMode/GetMode. Support both approachs will make the code messy!

Testing sample:
//SetMode sample the allowed values are: 0, 2 and 3 $dbus-send --system --print-reply --dest=org.bluez /org/bluez/Device/hci0 org.bluez.Device.SetMode byte:0

//GetMode sample
$dbus-send --system --print-reply --dest=org.bluez /org/bluez/Device/hci0 org.bluez.Device.GetMode

The dbus-test python script can be used too.

Regards,
Claudio.

Quoted 18 lines · Marcel Holtmann

Hi Eduardo,

Quoted 3 lines
Quoted 1 line

do you mean have both implementations (SetProperty("mode") and SetMode) ?

we can have both, but I would prefer the SetMode() stuff.

and if a device is in Connectable only mode it would be great if we have another method that makes this device discoverable for a specific time. For example make it discoverable for 3 minutes, like the early Ericsson phones did.

Regards

Marcel

Quoted 10 lines

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

hcid/dbus.h +12 -1
@@ -101,6 +101,7 @@
 
 /* /org/bluez/Device signals */
 #define BLUEZ_HCI_PROPERTY_CHANGED	"PropertyChanged"
+#define BLUEZ_HCI_SCAN_MODE_CHANGED	"ModeChanged"
 
 /* Control interface signals */
 #define BLUEZ_HCI_INQ_START		"InquiryStart"
@@ -125,6 +126,14 @@
 #define DEV_DOWN			"Down"
 #define DEV_SET_PROPERTY		"SetProperty"
 #define DEV_GET_PROPERTY		"GetProperty"
+#define DEV_SET_MODE			"SetMode"
+#define DEV_GET_MODE			"GetMode"
+
+/* SetMode constants, see Bluetooth spec write scan enable command section */
+#define MODE_SCAN_OFF			SCAN_DISABLED
+#define MODE_CONNECTABLE		SCAN_PAGE
+#define MODE_CONNECTABLE_DISCOVERABLE	(SCAN_PAGE | SCAN_INQUIRY)
+
 
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
@@ -136,7 +145,9 @@
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
-#define DEV_RESET_SIGNATURE			__END_SIG__
+#define DEV_SET_MODE_SIGNATURE			DBUS_TYPE_BYTE_AS_STRING\
+						__END_SIG__
+#define DEV_GET_MODE_SIGNATURE			__END_SIG__
 #define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
hcid/dbus.c +102 -122

284 lines not on this page · raw message

hcid/dbus-test +30 -6
@@ -9,10 +9,10 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry",
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "SetMode", "GetMode", "Inquiry",
              "CancelInquiry", "PeriodicInquiry","CancelPeriodic", "RemoteName",
              "Connections", "Authenticate", "RoleSwitch" ]
-dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
+dev_setprop_bool = [ "auth", "encrypt" ]
 dev_setprop_byte = [ "incmode" ]
 dev_prop_filter = ["/org/bluez/Device/hci0", "/org/bluez/Device/hci1",
                    "/org/bluez/Device/hci2", "/org/bluez/Device/hci3",
@@ -88,6 +88,10 @@
                     self.bus.add_signal_receiver(self.dev_property_changed,
                                              'PropertyChanged','org.bluez.Device',
                                              'org.bluez',path)
+                for path in dev_prop_filter:
+                    self.bus.add_signal_receiver(self.dev_mode_changed,
+                                             'ModeChanged','org.bluez.Device',
+                                             'org.bluez',path)
                 obj = self.bus.get_object('org.bluez', '%s/Controller' % self.dev_path)
                 self.ctl = dbus.Interface(obj, 'org.bluez.Device.Controller')
 
@@ -166,11 +170,12 @@
         dbus_message = keywords["dbus_message"]
         if property == 'name':
             print 'Device %s name changed: %s' % (dbus_message.get_path(), param)
-        elif property == 'connectable':
-            print 'Device %s connectable scan property changed: %d' % (dbus_message.get_path(), param)
-        elif property == 'discoverable':
-            print 'Device %s discoverable scan property changed: %d' % (dbus_message.get_path(), param)
 
+    @dbus.decorators.explicitly_pass_message
+    def dev_mode_changed(*args, **keywords):
+        mode = args[1]
+        dbus_message = keywords["dbus_message"]
+        print 'Device %s scan mode changed: %x' % (dbus_message.get_path(), mode)
 
     def signal_cb(self, sig, frame):
         print 'Caught signal, exiting'
@@ -224,6 +229,25 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
+        elif self.cmd == 'SetMode':
+            if len(self.cmd_args) != 1:
+                print 'Usage: %s -i <dev> SetMode scan_enable' % self.name
+                print 'scan_enable values: 0(no scan), 2(connectable), 3(connectable and discoverable)' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.SetMode(dbus.Byte(self.cmd_args[0]))
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        elif self.cmd == 'GetMode':
+            if len(self.cmd_args) != 0:
+                print 'Usage: %s -i <dev> GetMode' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.GetMode()
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:
author maintainer
#9 lore raw

Hi Claudio,

Quoted 7 lines

This patch is based on your discussion, but there are some changes:
1. The scan enable values are based on the Bluetooth Spec in order to make the logic more clear:

mode 0x00       = Off (means down or deep-sleep)
mode 0x01       = Discoverable (NOT ALLOWED)
mode 0x02       = Connectable
mode 0x03       = Connectable and Discoverable

actually I didn't used the values from the specification on purpose. On future idea is that we support discoverable for them time and the client doesn't have to take care when to switch inquiry scan off again. As I sometimes mentioned, it might be good to not follow the specification for the D-Bus API. The hcid/bluetoothd will hide all implementation details.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#10 lore raw

Hi Marcel,

Here is the patch following your suggestion.

Now, we introduced a problem. How handle scenarios where other application/or hciconfig changes the scan mode, enabling the Inquiry Scan only? :) In the current patch, I am ignoring the HCI command complete event for this case.

When we close this discussion I can start play with the discoverable time stuff.

Regards,
Claudio.

Quoted 24 lines · Marcel Holtmann

Hi Claudio,

Quoted 7 lines

This patch is based on your discussion, but there are some changes:
1. The scan enable values are based on the Bluetooth Spec in order to make the logic more clear:

mode 0x00       = Off (means down or deep-sleep)
mode 0x01       = Discoverable (NOT ALLOWED)
mode 0x02       = Connectable
mode 0x03       = Connectable and Discoverable

actually I didn't used the values from the specification on purpose. On future idea is that we support discoverable for them time and the client doesn't have to take care when to switch inquiry scan off again. As I sometimes mentioned, it might be good to not follow the specification for the D-Bus API. The hcid/bluetoothd will hide all implementation details.

Regards

Marcel

Quoted 10 lines

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

hcid/dbus.h +11 -1
@@ -101,6 +101,7 @@
 
 /* /org/bluez/Device signals */
 #define BLUEZ_HCI_PROPERTY_CHANGED	"PropertyChanged"
+#define BLUEZ_HCI_SCAN_MODE_CHANGED	"ModeChanged"
 
 /* Control interface signals */
 #define BLUEZ_HCI_INQ_START		"InquiryStart"
@@ -125,6 +126,13 @@
 #define DEV_DOWN			"Down"
 #define DEV_SET_PROPERTY		"SetProperty"
 #define DEV_GET_PROPERTY		"GetProperty"
+#define DEV_SET_MODE			"SetMode"
+#define DEV_GET_MODE			"GetMode"
+
+/* SetMode constants, see Bluetooth spec write scan enable command section */
+#define MODE_SCAN_OFF			0x00
+#define MODE_CONNECTABLE		0x01
+#define MODE_CONNECTABLE_DISCOVERABLE	0x02
 
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
@@ -136,7 +144,9 @@
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
-#define DEV_RESET_SIGNATURE			__END_SIG__
+#define DEV_SET_MODE_SIGNATURE			DBUS_TYPE_BYTE_AS_STRING\
+						__END_SIG__
+#define DEV_GET_MODE_SIGNATURE			__END_SIG__
 #define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
hcid/dbus.c +145 -124

327 lines not on this page · raw message

hcid/dbus-test +30 -6
@@ -9,10 +9,10 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry",
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "SetMode", "GetMode", "Inquiry",
              "CancelInquiry", "PeriodicInquiry","CancelPeriodic", "RemoteName",
              "Connections", "Authenticate", "RoleSwitch" ]
-dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
+dev_setprop_bool = [ "auth", "encrypt" ]
 dev_setprop_byte = [ "incmode" ]
 dev_prop_filter = ["/org/bluez/Device/hci0", "/org/bluez/Device/hci1",
                    "/org/bluez/Device/hci2", "/org/bluez/Device/hci3",
@@ -88,6 +88,10 @@
                     self.bus.add_signal_receiver(self.dev_property_changed,
                                              'PropertyChanged','org.bluez.Device',
                                              'org.bluez',path)
+                for path in dev_prop_filter:
+                    self.bus.add_signal_receiver(self.dev_mode_changed,
+                                             'ModeChanged','org.bluez.Device',
+                                             'org.bluez',path)
                 obj = self.bus.get_object('org.bluez', '%s/Controller' % self.dev_path)
                 self.ctl = dbus.Interface(obj, 'org.bluez.Device.Controller')
 
@@ -166,11 +170,12 @@
         dbus_message = keywords["dbus_message"]
         if property == 'name':
             print 'Device %s name changed: %s' % (dbus_message.get_path(), param)
-        elif property == 'connectable':
-            print 'Device %s connectable scan property changed: %d' % (dbus_message.get_path(), param)
-        elif property == 'discoverable':
-            print 'Device %s discoverable scan property changed: %d' % (dbus_message.get_path(), param)
 
+    @dbus.decorators.explicitly_pass_message
+    def dev_mode_changed(*args, **keywords):
+        mode = args[1]
+        dbus_message = keywords["dbus_message"]
+        print 'Device %s scan mode changed: %x' % (dbus_message.get_path(), mode)
 
     def signal_cb(self, sig, frame):
         print 'Caught signal, exiting'
@@ -224,6 +229,25 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
+        elif self.cmd == 'SetMode':
+            if len(self.cmd_args) != 1:
+                print 'Usage: %s -i <dev> SetMode scan_enable' % self.name
+                print 'scan_enable values: 0(no scan), 1(connectable), 2(connectable and discoverable)' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.SetMode(dbus.Byte(self.cmd_args[0]))
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        elif self.cmd == 'GetMode':
+            if len(self.cmd_args) != 0:
+                print 'Usage: %s -i <dev> GetMode' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.GetMode()
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:
author maintainer
#11 lore raw

Hi Claudio,

Quoted 1 line

Here is the patch following your suggestion.

cool, but the patch has some issues.

Don't refer to the Bluetooth specification for the mode values, because we define our own.

Please name the modes like following:

#define MODE_OFF           0x00
#define MODE_CONNECTABLE   0x01
#define MODE_DISCOVERABLE  0x02

The discoverable mode of course includes connectable mode.

In the handle_device_get_mode_req(), the switch statement always sets the mode to 0xff. Please add the breaks and if you write a fall through statement, then comment it.

Quoted 4 lines

Now, we introduced a problem. How handle scenarios where other application/or hciconfig changes the scan mode, enabling the Inquiry Scan only? :) In the current patch, I am ignoring the HCI command complete event for this case.

We need to track the scan mode command complete event and if the mode changes, we need to send out a mode change signal.

Quoted 1 line

When we close this discussion I can start play with the discoverable time stuff.

That would be really great, because this feature could come in handy for any graphical application.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

#12 lore raw

Hi Marcel,

here is the new patch!

You can use the command below or the dbus-test script to test this feature. $dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/Device/hci0 org.bluez.Device.SetMode byte:0

$dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/Device/hci0 org.bluez.Device.GetMode

I will send tomorrow a new version of the GBlueZConf with this feature.

Regards,
Claudio.

Quoted 41 lines · Marcel Holtmann

Hi Claudio,

Quoted 1 line

Here is the patch following your suggestion.

cool, but the patch has some issues.

Don't refer to the Bluetooth specification for the mode values, because we define our own.

Please name the modes like following:

#define MODE_OFF           0x00
#define MODE_CONNECTABLE   0x01
#define MODE_DISCOVERABLE  0x02

The discoverable mode of course includes connectable mode.

In the handle_device_get_mode_req(), the switch statement always sets the mode to 0xff. Please add the breaks and if you write a fall through statement, then comment it.

Quoted 4 lines

Now, we introduced a problem. How handle scenarios where other application/or hciconfig changes the scan mode, enabling the Inquiry Scan only? :) In the current patch, I am ignoring the HCI command complete event for this case.

We need to track the scan mode command complete event and if the mode changes, we need to send out a mode change signal.

Quoted 1 line

When we close this discussion I can start play with the discoverable time stuff.

That would be really great, because this feature could come in handy for any graphical application.

Regards

Marcel

Quoted 10 lines

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel

--
---------------------------------------------------------
Claudio Takahasi
Instituto Nokia de Tecnologia - INdT

hcid/dbus.h +18 -1
@@ -101,6 +101,7 @@
 
 /* /org/bluez/Device signals */
 #define BLUEZ_HCI_PROPERTY_CHANGED	"PropertyChanged"
+#define BLUEZ_HCI_SCAN_MODE_CHANGED	"ModeChanged"
 
 /* Control interface signals */
 #define BLUEZ_HCI_INQ_START		"InquiryStart"
@@ -125,6 +126,20 @@
 #define DEV_DOWN			"Down"
 #define DEV_SET_PROPERTY		"SetProperty"
 #define DEV_GET_PROPERTY		"GetProperty"
+#define DEV_SET_MODE			"SetMode"
+#define DEV_GET_MODE			"GetMode"
+
+/*
+ * Scanning modes
+ * off: remote devices are not allowed to find or connect to this device
+ * connectable: remote devices are allowed to connect, but they are not
+ *              allowed to find it.
+ * discoverable: remote devices are allowed to connect and find this device
+ */
+#define MODE_OFF			0x00
+#define MODE_CONNECTABLE		0x01
+#define MODE_DISCOVERABLE		0x02
+
 
 #define DEV_PROPERTY_AUTH		"auth"
 #define DEV_PROPERTY_ENCRYPT		"encrypt"
@@ -136,7 +151,9 @@
 
 #define DEV_UP_SIGNATURE			__END_SIG__
 #define DEV_DOWN_SIGNATURE			__END_SIG__
-#define DEV_RESET_SIGNATURE			__END_SIG__
+#define DEV_SET_MODE_SIGNATURE			DBUS_TYPE_BYTE_AS_STRING\
+						__END_SIG__
+#define DEV_GET_MODE_SIGNATURE			__END_SIG__
 #define DEV_SET_PROPERTY_SIGNATURE_BOOL		DBUS_TYPE_STRING_AS_STRING \
 						DBUS_TYPE_BOOLEAN_AS_STRING \
 						__END_SIG__
hcid/dbus.c +150 -124

332 lines not on this page · raw message

hcid/dbus-test +30 -6
@@ -9,10 +9,10 @@
 from signal import *
 
 mgr_cmds = [ "DeviceList", "DefaultDevice" ]
-dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "Inquiry",
+dev_cmds = [ "Up", "Down", "SetProperty", "GetProperty", "SetMode", "GetMode", "Inquiry",
              "CancelInquiry", "PeriodicInquiry","CancelPeriodic", "RemoteName",
              "Connections", "Authenticate", "RoleSwitch" ]
-dev_setprop_bool = [ "auth", "encrypt", "discoverable", "connectable" ]
+dev_setprop_bool = [ "auth", "encrypt" ]
 dev_setprop_byte = [ "incmode" ]
 dev_prop_filter = ["/org/bluez/Device/hci0", "/org/bluez/Device/hci1",
                    "/org/bluez/Device/hci2", "/org/bluez/Device/hci3",
@@ -88,6 +88,10 @@
                     self.bus.add_signal_receiver(self.dev_property_changed,
                                              'PropertyChanged','org.bluez.Device',
                                              'org.bluez',path)
+                for path in dev_prop_filter:
+                    self.bus.add_signal_receiver(self.dev_mode_changed,
+                                             'ModeChanged','org.bluez.Device',
+                                             'org.bluez',path)
                 obj = self.bus.get_object('org.bluez', '%s/Controller' % self.dev_path)
                 self.ctl = dbus.Interface(obj, 'org.bluez.Device.Controller')
 
@@ -166,11 +170,12 @@
         dbus_message = keywords["dbus_message"]
         if property == 'name':
             print 'Device %s name changed: %s' % (dbus_message.get_path(), param)
-        elif property == 'connectable':
-            print 'Device %s connectable scan property changed: %d' % (dbus_message.get_path(), param)
-        elif property == 'discoverable':
-            print 'Device %s discoverable scan property changed: %d' % (dbus_message.get_path(), param)
 
+    @dbus.decorators.explicitly_pass_message
+    def dev_mode_changed(*args, **keywords):
+        mode = args[1]
+        dbus_message = keywords["dbus_message"]
+        print 'Device %s scan mode changed: %x' % (dbus_message.get_path(), mode)
 
     def signal_cb(self, sig, frame):
         print 'Caught signal, exiting'
@@ -224,6 +229,25 @@
             except dbus.DBusException, e:
                 print 'Sending %s failed: %s' % (self.cmd, e)
                 sys.exit(1)
+        elif self.cmd == 'SetMode':
+            if len(self.cmd_args) != 1:
+                print 'Usage: %s -i <dev> SetMode scan_enable' % self.name
+                print 'scan_enable values: 0(no scan), 1(connectable), 2(connectable and discoverable)' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.SetMode(dbus.Byte(self.cmd_args[0]))
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
+        elif self.cmd == 'GetMode':
+            if len(self.cmd_args) != 0:
+                print 'Usage: %s -i <dev> GetMode' % self.name
+                sys.exit(1)
+            try:
+                print self.dev.GetMode()
+            except dbus.DBusException, e:
+                print 'Sending %s failed: %s' % (self.cmd, e)
+                sys.exit(1)
         # Device.Controller methods
         elif self.cmd == 'Inquiry':
             try:
author maintainer
#13 lore raw

Hi Claudio,

Quoted 8 lines

here is the new patch!

You can use the command below or the dbus-test script to test this feature. $dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/Device/hci0 org.bluez.Device.SetMode byte:0

$dbus-send --system --print-reply --type=method_call --dest=org.bluez /org/bluez/Device/hci0 org.bluez.Device.GetMode

the patch has been applied to the CVS now.

Regards

Marcel

-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel