diff options
-rw-r--r-- | hcid/dbus-database.c | 10 | ||||
-rw-r--r-- | hcid/main.c | 52 | ||||
-rw-r--r-- | hcid/manager.c | 53 | ||||
-rw-r--r-- | hcid/manager.h | 2 | ||||
-rw-r--r-- | sdpd/sdpd.h | 3 | ||||
-rw-r--r-- | sdpd/service.c | 9 |
6 files changed, 64 insertions, 65 deletions
diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 384df032..29e5b132 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -86,8 +86,6 @@ 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); @@ -148,8 +146,6 @@ static DBusHandlerResult add_service_record(DBusConnection *conn, } } - update_class_of_device(); - sender = dbus_message_get_sender(msg); user_record->sender = g_strdup(sender); @@ -211,8 +207,6 @@ 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); @@ -262,8 +256,6 @@ static DBusHandlerResult update_record(DBusConnection *conn, DBusMessage *msg, } } - update_class_of_device(); - return send_message_and_unref(conn, dbus_message_new_method_return(msg)); } @@ -366,8 +358,6 @@ 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/main.c b/hcid/main.c index 6539642d..90461274 100644 --- a/hcid/main.c +++ b/hcid/main.c @@ -243,6 +243,57 @@ no_address: return device_opts->discovto; } +void update_service_classes(const bdaddr_t *bdaddr, uint8_t value) +{ + struct hci_dev_list_req *dl; + struct hci_dev_req *dr; + int i, sk; + + sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); + if (sk < 0) + return; + + 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 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; + + set_service_classes(dd, cls, value); + + hci_close_dev(dd); + } + + g_free(dl); + + close(sk); +} + /* * Device name expansion * %d - device id @@ -884,6 +935,7 @@ int main(int argc, char *argv[]) if (sdp) { set_sdp_server_enable(); start_sdp_server(mtu, hcid.deviceid, SDP_SERVER_COMPAT); + set_service_classes_callback(update_service_classes); } notify_init(); diff --git a/hcid/manager.c b/hcid/manager.c index a5588c4b..8e0652cc 100644 --- a/hcid/manager.c +++ b/hcid/manager.c @@ -329,56 +329,3 @@ void set_default_adapter(int new_default) { default_adapter_id = new_default; } - -void update_class_of_device(void) -{ - struct hci_dev_list_req *dl; - struct hci_dev_req *dr; - int i, sk; - - sk = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HCI); - if (sk < 0) - return; - - 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); - - hci_close_dev(dd); - } - - g_free(dl); - - close(sk); -} diff --git a/hcid/manager.h b/hcid/manager.h index 41127bab..eef0dd36 100644 --- a/hcid/manager.h +++ b/hcid/manager.h @@ -28,5 +28,3 @@ 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); diff --git a/sdpd/sdpd.h b/sdpd/sdpd.h index 6fc60e85..ad7a2d4f 100644 --- a/sdpd/sdpd.h +++ b/sdpd/sdpd.h @@ -87,4 +87,7 @@ void stop_sdp_server(void); int add_record_to_server(sdp_record_t *rec); int remove_record_from_server(uint32_t handle); +typedef void (*service_classes_callback_t) (const bdaddr_t *bdaddr, uint8_t value); + uint8_t get_service_classes(const bdaddr_t *bdaddr); +void set_service_classes_callback(service_classes_callback_t callback); diff --git a/sdpd/service.c b/sdpd/service.c index 851c1459..7f8296f4 100644 --- a/sdpd/service.c +++ b/sdpd/service.c @@ -45,6 +45,7 @@ static sdp_record_t *server = NULL; static uint8_t service_classes = 0x00; +static service_classes_callback_t service_classes_callback = NULL; /* * List of version numbers supported by the SDP server. @@ -123,6 +124,9 @@ static void update_svclass_list(void) debug("Service classes 0x%02x", val); service_classes = val; + + if (service_classes_callback) + service_classes_callback(BDADDR_ANY, val); } uint8_t get_service_classes(const bdaddr_t *bdaddr) @@ -130,6 +134,11 @@ uint8_t get_service_classes(const bdaddr_t *bdaddr) return service_classes; } +void set_service_classes_callback(service_classes_callback_t callback) +{ + service_classes_callback = callback; +} + void register_public_browse_group(void) { sdp_list_t *browselist; |