Add "Class" property to org.bluez.Adapter
PATCH 1/1 Add "Class" property to org.bluez.Adapter
Hi Marcel,
I mentioned on IRC a while back that a "Class" property for the Adapter interface might be useful. I've attached a patch to this effect. Please let me know if there are any issues.
cheers,
Bea
doc/adapter-api.txt +4 -0
@@ -210,6 +210,10 @@ Properties string Address [readonly] The Bluetooth friendly name. This value can be changed and a PropertyChanged signal will be emitted. + uint32 Class [readonly] + + The Bluetooth class of device. + boolean Powered [readwrite] Switch an adapter on or off. This will also set the
src/adapter.c +20 -0
@@ -1192,6 +1192,7 @@ static DBusMessage *get_properties(DBusConnection *conn,DBusMessageIter iter;DBusMessageIter dict;char str[249 ], srcaddr[18 ]; +uint32_t class;gboolean value;char **devices;int i;
@@ -1224,6 +1225,12 @@ static DBusMessage *get_properties(DBusConnection *conn,dict_append_entry (&dict,"Name" ,DBUS_TYPE_STRING , &property); +/* Class */ + class = adapter->dev.class[0 ] + | (adapter->dev.class[1 ] <<8 ) + | (adapter->dev.class[2 ] <<16 ); +dict_append_entry (&dict,"Class" ,DBUS_TYPE_UINT32 , &class); +/* Powered */ value = adapter->up ? TRUE : FALSE;dict_append_entry (&dict,"Powered" ,DBUS_TYPE_BOOLEAN , &value);
@@ -2326,6 +2333,8 @@ int adapter_get_class(struct btd_adapter *adapter, uint8_t *cls)int adapter_set_class (struct btd_adapter *adapter,uint8_t *cls) {struct hci_dev *dev = &adapter->dev; +int dd; +uint32_t class;if (memcmp (dev->class, cls,3 ) ==0 )return 0 ;
@@ -2334,6 +2343,17 @@ int adapter_set_class(struct btd_adapter *adapter, uint8_t *cls)write_local_class (&adapter->bdaddr, cls); + dd =hci_open_dev (adapter->dev_id); +if (dd >=0 ) { +update_ext_inquiry_response (dd, dev); +hci_close_dev (dd); + } + + class = cls[0 ] | (cls[1 ] <<8 ) | (cls[2 ] <<16 ); + +emit_property_changed (connection, adapter->path,ADAPTER_INTERFACE , +"Class" ,DBUS_TYPE_UINT32 , &class); +return 0 ; }
Marcel Holtmann
maintainerHi Bea,
Quoted 3 lines
I mentioned on IRC a while back that a "Class" property for the Adapter interface might be useful. I've attached a patch to this effect. Please let me know if there are any issues.
+ /* Class */
+ class = adapter->dev.class[0]
+ | (adapter->dev.class[1] << 8)
+ | (adapter->dev.class[2] << 16);
+ dict_append_entry(&dict, "Class", DBUS_TYPE_UINT32, &class);
+
This should more like this:
class = adapter->dev.class[0] | adapter->dev.class[1] << 8 | ...
Regards
Marcel
Hi Marcel,
Quoted 7 lines
(quoted diff) +6
-0+ /* Class */ + class = adapter->dev.class[0] + | (adapter->dev.class[1] << 8) + | (adapter->dev.class[2] << 16); + dict_append_entry(&dict, "Class", DBUS_TYPE_UINT32, &class); +
Quoted 5 lines
This should more like this:
class = adapter->dev.class[0] | adapter->dev.class[1] << 8 | ...
The revised patch is attached. The original format was based on similar code in security.c.
Thanks
Bea
doc/adapter-api.txt +4 -0
@@ -210,6 +210,10 @@ Properties string Address [readonly] The Bluetooth friendly name. This value can be changed and a PropertyChanged signal will be emitted. + uint32 Class [readonly] + + The Bluetooth class of device. + boolean Powered [readwrite] Switch an adapter on or off. This will also set the
src/adapter.c +20 -0
@@ -1192,6 +1192,7 @@ static DBusMessage *get_properties(DBusConnection *conn,DBusMessageIter iter;DBusMessageIter dict;char str[249 ], srcaddr[18 ]; +uint32_t class;gboolean value;char **devices;int i;
@@ -1224,6 +1225,12 @@ static DBusMessage *get_properties(DBusConnection *conn,dict_append_entry (&dict,"Name" ,DBUS_TYPE_STRING , &property); +/* Class */ + class = adapter->dev.class[0 ] | + adapter->dev.class[1 ] <<8 | + adapter->dev.class[2 ] <<16 ; +dict_append_entry (&dict,"Class" ,DBUS_TYPE_UINT32 , &class); +/* Powered */ value = adapter->up ? TRUE : FALSE;dict_append_entry (&dict,"Powered" ,DBUS_TYPE_BOOLEAN , &value);
@@ -2326,6 +2333,8 @@ int adapter_get_class(struct btd_adapter *adapter, uint8_t *cls)int adapter_set_class (struct btd_adapter *adapter,uint8_t *cls) {struct hci_dev *dev = &adapter->dev; +int dd; +uint32_t class;if (memcmp (dev->class, cls,3 ) ==0 )return 0 ;
@@ -2334,6 +2343,17 @@ int adapter_set_class(struct btd_adapter *adapter, uint8_t *cls)write_local_class (&adapter->bdaddr, cls); + dd =hci_open_dev (adapter->dev_id); +if (dd >=0 ) { +update_ext_inquiry_response (dd, dev); +hci_close_dev (dd); + } + + class = cls[0 ] | (cls[1 ] <<8 ) | (cls[2 ] <<16 ); + +emit_property_changed (connection, adapter->path,ADAPTER_INTERFACE , +"Class" ,DBUS_TYPE_UINT32 , &class); +return 0 ; }
Hi Bea,
Quoted 2 lines · Bea Lam
The revised patch is attached. The original format was based on similar code in
security.c.
I can apply the patch but could you first create a proper version of it with git format-patch so that I don't have to start manipulating GIT_AUTHOR_NAME etc. myself. (I realize this isn't much work for myself either but it'd be good to get everyone submitting patches into this habit since otherwise the workload on our (me & Marcel) side starts accumulating pretty quickly.) Thanks.
Johan
Hi Johan,
Quoted 6 lines
I can apply the patch but could you first create a proper version of it with git format-patch so that I don't have to start manipulating
GIT_AUTHOR_NAMEetc. myself. (I realize this isn't much work for myself either but it'd be good to get everyone submitting patches into this habit since otherwise the workload on our (me & Marcel) side starts accumulating pretty quickly.) Thanks.
Here's the formatted patch, without the unnecessary update_ext_inquiry_response() call.
Thanks,
Bea
Quoted 1 line
From
6d1e1d52effae8ac1e2d9210267b6e85b86a7dbdMon Sep 17 00:00:00 2001
From: Bea Lam <[email protected]>
Date: Mon, 16 Mar 2009 11:32:06 +1000
Subject: [PATCH] Add "Class" property to org.bluez.Adapter interface.
--- doc/adapter-api.txt | 4 ++++ src/adapter.c | 13 +++++++++++++ 2 files changed, 17 insertions(+), 0 deletions(-)
doc/adapter-api.txt +4 -0
@@ -210,6 +210,10 @@ Properties string Address [readonly] The Bluetooth friendly name. This value can be changed and a PropertyChanged signal will be emitted. + uint32 Class [readonly] + + The Bluetooth class of device. + boolean Powered [readwrite] Switch an adapter on or off. This will also set the
src/adapter.c +13 -0
@@ -1192,6 +1192,7 @@ static DBusMessage *get_properties(DBusConnection *conn,DBusMessageIter iter;DBusMessageIter dict;char str[249 ], srcaddr[18 ]; +uint32_t class;gboolean value;char **devices;int i;
@@ -1224,6 +1225,12 @@ static DBusMessage *get_properties(DBusConnection *conn,dict_append_entry (&dict,"Name" ,DBUS_TYPE_STRING , &property); +/* Class */ + class = adapter->dev.class[0 ] | + adapter->dev.class[1 ] <<8 | + adapter->dev.class[2 ] <<16 ; +dict_append_entry (&dict,"Class" ,DBUS_TYPE_UINT32 , &class); +/* Powered */ value = adapter->up ? TRUE : FALSE;dict_append_entry (&dict,"Powered" ,DBUS_TYPE_BOOLEAN , &value);
@@ -2326,6 +2333,7 @@ int adapter_get_class(struct btd_adapter *adapter, uint8_t *cls)int adapter_set_class (struct btd_adapter *adapter,uint8_t *cls) {struct hci_dev *dev = &adapter->dev; +uint32_t class;if (memcmp (dev->class, cls,3 ) ==0 )return 0 ;
@@ -2334,6 +2342,11 @@ int adapter_set_class(struct btd_adapter *adapter, uint8_t *cls)write_local_class (&adapter->bdaddr, cls); + class = cls[0 ] | (cls[1 ] <<8 ) | (cls[2 ] <<16 ); + +emit_property_changed (connection, adapter->path,ADAPTER_INTERFACE , +"Class" ,DBUS_TYPE_UINT32 , &class); +return 0 ; }
Signature · 1 line
1.6.1
Hi Bea,
Quoted 2 lines · Bea Lam
Here's the formatted patch, without the unnecessary
update_ext_inquiry_response()call.
Thanks! The patch is now pushed upstream. Unfortunately you just missed the 4.33 release (Marcel already tagged it) so your patch will go into 4.34.
Johan