diff options
author | Marcel Holtmann <marcel@holtmann.org> | 2007-08-22 01:50:41 +0000 |
---|---|---|
committer | Marcel Holtmann <marcel@holtmann.org> | 2007-08-22 01:50:41 +0000 |
commit | b22d297c0c679b400d7825367e31fed46c552a49 (patch) | |
tree | 48f403d960004356af7ce70bedfc4f2490231945 /hcid | |
parent | 145dfdd4b2e09f6b5b9e0be03d134c0242261b81 (diff) |
First attempt for automatic setting of service classes value
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-database.c | 11 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 24 | ||||
-rw-r--r-- | hcid/dbus-hci.h | 1 | ||||
-rw-r--r-- | hcid/hcid.conf | 2 | ||||
-rw-r--r-- | hcid/main.c | 3 | ||||
-rw-r--r-- | hcid/manager.c | 26 | ||||
-rw-r--r-- | hcid/manager.h | 2 |
7 files changed, 66 insertions, 3 deletions
diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 1c770c83..384df032 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -44,6 +44,7 @@ #include "hcid.h" #include "sdpd.h" #include "sdp-xml.h" +#include "manager.h" #include "adapter.h" #include "dbus-hci.h" #include "dbus-common.h" @@ -85,6 +86,8 @@ static void exit_callback(const char *name, void *user_data) else unregister_sdp_record(user_record->handle); + update_class_of_device(); + if (user_record->sender) g_free(user_record->sender); @@ -145,6 +148,8 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, } } + update_class_of_device(); + sender = dbus_message_get_sender(msg); user_record->sender = g_strdup(sender); @@ -206,6 +211,8 @@ static DBusHandlerResult add_service_record_from_xml(DBusConnection *conn, sdp_record_free(sdp_record); } + update_class_of_device(); + sender = dbus_message_get_sender(msg); user_record->sender = g_strdup(sender); @@ -255,6 +262,8 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, } } + update_class_of_device(); + return send_message_and_unref(conn, dbus_message_new_method_return(msg)); } @@ -357,6 +366,8 @@ static DBusHandlerResult remove_service_record(DBusConnection *conn, else unregister_sdp_record(handle); + update_class_of_device(); + if (user_record->sender) g_free(user_record->sender); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index a8ae676c..77a93421 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -1666,8 +1666,28 @@ int set_limited_discoverable(int dd, const uint8_t *cls, gboolean limited) if (hci_write_class_of_dev(dd, dev_class, 1000) < 0) { err = errno; - error("Can't write class of device: %s(%d)", - strerror(err), err); + error("Can't write class of device: %s (%d)", + strerror(err), err); + return -err; + } + + return 0; +} + +int set_service_classes(int dd, const uint8_t *cls, uint8_t value) +{ + uint32_t dev_class; + int err; + + if (cls[2] == value) + return 0; /* Already set */ + + dev_class = (value << 16) | (cls[1] << 8) | cls[0]; + + if (hci_write_class_of_dev(dd, dev_class, 1000) < 0) { + err = errno; + error("Can't write class of device: %s (%d)", + strerror(err), err); return -err; } diff --git a/hcid/dbus-hci.h b/hcid/dbus-hci.h index 385ed96c..6c0a662f 100644 --- a/hcid/dbus-hci.h +++ b/hcid/dbus-hci.h @@ -69,6 +69,7 @@ int found_device_add(GSList **list, bdaddr_t *bdaddr, int8_t rssi, int found_device_req_name(struct adapter *dbus_data); int set_limited_discoverable(int dd, const uint8_t *cls, gboolean limited); +int set_service_classes(int dd, const uint8_t *cls, uint8_t value); int discov_timeout_handler(void *data); diff --git a/hcid/hcid.conf b/hcid/hcid.conf index 77c743a7..b6ce3b48 100644 --- a/hcid/hcid.conf +++ b/hcid/hcid.conf @@ -32,7 +32,7 @@ device { name "BlueZ (%d)"; # Local device class - class 0x3e0100; + class 0x000100; # Default packet type #pkt_type DH1,DM1,HV1; diff --git a/hcid/main.c b/hcid/main.c index bd470c87..75229fba 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -467,12 +467,15 @@ static void configure_device(int dev_id) if (read_local_class(&di.bdaddr, cls) < 0) { class = htobl(device_opts->class); + cls[2] = get_service_classes(); memcpy(cp.dev_class, &class, 3); } else { if (!(device_opts->scan & SCAN_INQUIRY)) cls[1] &= 0xdf; /* Clear discoverable bit */ + cls[2] = get_service_classes(); memcpy(cp.dev_class, cls, 3); } + hci_send_cmd(dd, OGF_HOST_CTL, OCF_WRITE_CLASS_OF_DEV, WRITE_CLASS_OF_DEV_CP_SIZE, &cp); } diff --git a/hcid/manager.c b/hcid/manager.c index 50cd698e..c03cdc3f 100644 --- a/hcid/manager.c +++ b/hcid/manager.c @@ -42,6 +42,7 @@ #include <dbus/dbus.h> #include "hcid.h" +#include "sdpd.h" #include "adapter.h" #include "dbus.h" #include "dbus-helper.h" @@ -328,3 +329,28 @@ void set_default_adapter(int new_default) { default_adapter_id = new_default; } + +void update_class_of_device(void) +{ + uint8_t value = get_service_classes(); + uint8_t cls[3]; + int dd, dev_id = default_adapter_id; + + if (dev_id < 0) + return; + + dd = hci_open_dev(dev_id); + if (dd < 0) + return; + + if (hci_read_class_of_dev(dd, cls, 1000) < 0) { + error("Can't read class of device on hci%d: %s (%d)", + dev_id, strerror(errno), errno); + hci_close_dev(dd); + return; + } + + set_service_classes(dd, cls, value); + + hci_close_dev(dd); +} diff --git a/hcid/manager.h b/hcid/manager.h index eef0dd36..41127bab 100644 --- a/hcid/manager.h +++ b/hcid/manager.h @@ -28,3 +28,5 @@ dbus_bool_t manager_init(DBusConnection *conn, const char *path); int get_default_adapter(void); void set_default_adapter(int new_default); + +void update_class_of_device(void); |