From 8612cbc529135b6c37ff80c4ff0ae63f822f321c Mon Sep 17 00:00:00 2001 From: Marcin Kraglak Date: Tue, 12 Nov 2013 16:36:25 +0100 Subject: [PATCH] android: Add support for getting UUIDs property This method will call adapter_properties_cb with uuids of adapter. Method is called also when uuid is added or removed. --- android/adapter.c | 55 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/android/adapter.c b/android/adapter.c index f3281ee30..87e4a2172 100644 --- a/android/adapter.c +++ b/android/adapter.c @@ -997,6 +997,45 @@ static void uuid16_to_uint128(uint16_t uuid, uint128_t *u128) ntoh128(&uuid128.value.uuid128, u128); } +static bool get_uuids(void) +{ + struct hal_ev_adapter_props_changed *ev; + GSList *list = adapter->uuids; + unsigned int uuid_count = g_slist_length(list); + int len = uuid_count * sizeof(uint128_t); + uint8_t buf[BASELEN_PROP_CHANGED + len]; + uint8_t *p; + int i; + + memset(buf, 0, sizeof(buf)); + ev = (void *) buf; + + ev->num_props = 1; + ev->status = HAL_STATUS_SUCCESS; + + ev->props[0].type = HAL_PROP_ADAPTER_UUIDS; + ev->props[0].len = len; + p = ev->props->val; + + for (; list; list = g_slist_next(list)) { + uint16_t uuid = GPOINTER_TO_UINT(list->data); + uint128_t uint128; + + uuid16_to_uint128(uuid, &uint128); + + /* Android expects swapped bytes in uuid */ + for (i = 0; i < 16; i++) + p[15 - i] = uint128.data[i]; + + p += sizeof(uint128_t); + } + + ipc_send(notification_sk, HAL_SERVICE_ID_BLUETOOTH, + HAL_EV_ADAPTER_PROPS_CHANGED, sizeof(buf), ev, -1); + + return true; +} + static void remove_uuid_complete(uint8_t status, uint16_t length, const void *param, void *user_data) { @@ -1007,6 +1046,10 @@ static void remove_uuid_complete(uint8_t status, uint16_t length, } mgmt_dev_class_changed_event(adapter->index, length, param, NULL); + + /* send notification only if bluetooth service is registered */ + if (notification_sk >= 0) + get_uuids(); } static void remove_uuid(uint16_t uuid) @@ -1032,6 +1075,10 @@ static void add_uuid_complete(uint8_t status, uint16_t length, } mgmt_dev_class_changed_event(adapter->index, length, param, NULL); + + /* send notification only if bluetooth service is registered */ + if (notification_sk >= 0) + get_uuids(); } static void add_uuid(uint8_t svc_hint, uint16_t uuid) @@ -1345,14 +1392,6 @@ static bool get_name(void) return true; } -static bool get_uuids(void) -{ - DBG("Not implemented"); - - /* TODO: Add implementation */ - - return false; -} static bool get_class(void) { -- 2.47.3