summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2007-08-23 09:48:14 +0000
committerMarcel Holtmann <marcel@holtmann.org>2007-08-23 09:48:14 +0000
commitf205cd06dc4e9da2c1d5109e570008d7d80b8380 (patch)
treea38b315e6880e1795f1255b7f42eef9aa5b23231
parentd4b3c37d8dc33d144559a10fdd826b853b6d11a0 (diff)
Update service classes on all adapters
-rw-r--r--hcid/dbus-hci.c1
-rw-r--r--hcid/device.c11
-rw-r--r--hcid/hcid.h1
-rw-r--r--hcid/main.c4
-rw-r--r--hcid/manager.c52
-rw-r--r--sdpd/sdpd.h2
-rw-r--r--sdpd/service.c2
7 files changed, 57 insertions, 16 deletions
diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c
index 77a93421..80aeb28c 100644
--- a/hcid/dbus-hci.c
+++ b/hcid/dbus-hci.c
@@ -1893,6 +1893,7 @@ void hcid_dbus_write_class_complete(bdaddr_t *local)
}
write_local_class(local, cls);
+ set_device_class(adapter->dev_id, cls);
memcpy(adapter->class, cls, 3);
hci_close_dev(dd);
diff --git a/hcid/device.c b/hcid/device.c
index 3c4f960d..983071d0 100644
--- a/hcid/device.c
+++ b/hcid/device.c
@@ -401,6 +401,17 @@ int get_device_class(uint16_t dev_id, uint8_t *cls)
return 0;
}
+int set_device_class(uint16_t dev_id, uint8_t *cls)
+{
+ struct hci_dev *dev;
+
+ ASSERT_DEV_ID;
+ dev = &devices[dev_id];
+ memcpy(dev->class, cls, 3);
+
+ return 0;
+}
+
int get_device_version(uint16_t dev_id, char *version, size_t size)
{
struct hci_dev *dev;
diff --git a/hcid/hcid.h b/hcid/hcid.h
index cffbd8c6..4e96afe4 100644
--- a/hcid/hcid.h
+++ b/hcid/hcid.h
@@ -163,6 +163,7 @@ int stop_adapter(uint16_t dev_id);
int get_device_address(uint16_t dev_id, char *address, size_t size);
int get_device_class(uint16_t dev_id, uint8_t *class);
+int set_device_class(uint16_t dev_id, uint8_t *class);
int get_device_version(uint16_t dev_id, char *version, size_t size);
int get_device_revision(uint16_t dev_id, char *revision, size_t size);
int get_device_manufacturer(uint16_t dev_id, char *manufacturer, size_t size);
diff --git a/hcid/main.c b/hcid/main.c
index 75229fba..6539642d 100644
--- a/hcid/main.c
+++ b/hcid/main.c
@@ -467,12 +467,12 @@ 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();
+ cls[2] = get_service_classes(&di.bdaddr);
memcpy(cp.dev_class, &class, 3);
} else {
if (!(device_opts->scan & SCAN_INQUIRY))
cls[1] &= 0xdf; /* Clear discoverable bit */
- cls[2] = get_service_classes();
+ cls[2] = get_service_classes(&di.bdaddr);
memcpy(cp.dev_class, cls, 3);
}
diff --git a/hcid/manager.c b/hcid/manager.c
index c03cdc3f..a5588c4b 100644
--- a/hcid/manager.c
+++ b/hcid/manager.c
@@ -332,25 +332,53 @@ void set_default_adapter(int 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;
+ struct hci_dev_list_req *dl;
+ struct hci_dev_req *dr;
+ int i, sk;
- if (dev_id < 0)
+ sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI);
+ if (sk < 0)
return;
- dd = hci_open_dev(dev_id);
- if (dd < 0)
+ dl = g_malloc0(HCI_MAX_DEV * sizeof(*dr) + sizeof(*dl));
+
+ dl->dev_num = HCI_MAX_DEV;
+ dr = dl->dev_req;
+
+ if (ioctl(sk, HCIGETDEVLIST, dl) < 0) {
+ close(sk);
+ g_free(dl);
return;
+ }
+
+ dr = dl->dev_req;
+
+ for (i = 0; i < dl->dev_num; i++, dr++) {
+ struct hci_dev_info di;
+ uint8_t value, cls[3];
+ int dd;
+
+ if (hci_devinfo(dr->dev_id, &di) < 0)
+ continue;
+
+ if (hci_test_bit(HCI_RAW, &di.flags))
+ continue;
+
+ if (get_device_class(di.dev_id, cls) < 0)
+ continue;
+
+ dd = hci_open_dev(di.dev_id);
+ if (dd < 0)
+ continue;
+
+ value = get_service_classes(&di.bdaddr);
+
+ set_service_classes(dd, cls, value);
- 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);
+ g_free(dl);
- hci_close_dev(dd);
+ close(sk);
}
diff --git a/sdpd/sdpd.h b/sdpd/sdpd.h
index dbb1ee09..6fc60e85 100644
--- a/sdpd/sdpd.h
+++ b/sdpd/sdpd.h
@@ -87,4 +87,4 @@ void stop_sdp_server(void);
int add_record_to_server(sdp_record_t *rec);
int remove_record_from_server(uint32_t handle);
-uint8_t get_service_classes(void);
+uint8_t get_service_classes(const bdaddr_t *bdaddr);
diff --git a/sdpd/service.c b/sdpd/service.c
index a75c0ed7..851c1459 100644
--- a/sdpd/service.c
+++ b/sdpd/service.c
@@ -125,7 +125,7 @@ static void update_svclass_list(void)
service_classes = val;
}
-uint8_t get_service_classes(void)
+uint8_t get_service_classes(const bdaddr_t *bdaddr)
{
return service_classes;
}