return BT_STATUS_SUCCESS;
}
+/* Get Local services API and callback */
+static gboolean __bt_adapter_service_uuids_cb(gpointer user_data)
+{
+ GVariant *result = user_data;
+ GVariant *temp;
+ GVariantIter *iter = NULL;
+ gchar *uuid_str;
+
+ /* Buffer and propety count management */
+ uint8_t buf[BT_MAX_PROPERTY_BUF_SIZE];
+ struct hal_ev_adapter_props_changed *ev = (void*) buf;
+ size_t size = 0;
+
+ /* UUID collection */
+ uint8_t uuids[HAL_UUID_LEN * MAX_UUID_COUNT];
+ int uuid_count = 0;
+
+ memset(buf, 0, sizeof(buf));
+ size = sizeof(*ev);
+ ev->num_props = 0;
+ ev->status = BT_STATUS_SUCCESS;
+
+ g_variant_get(result, "(v)", &temp);
+ g_variant_get(temp, "as", &iter);
+ if (iter == NULL) {
+ ERR("Failed to get UUIDs");
+ goto fail;
+ }
+
+ while (g_variant_iter_loop(iter, "s", &uuid_str)) {
+ uint8_t uuid[HAL_UUID_LEN];
+
+ DBG("UUID string [%s]\n", uuid_str);
+ _bt_convert_uuid_string_to_type(uuid, uuid_str);
+ memcpy(uuids + uuid_count * HAL_UUID_LEN, uuid, HAL_UUID_LEN);
+ uuid_count++;
+ }
+
+ size += __bt_insert_hal_properties(buf + size,
+ HAL_PROP_ADAPTER_UUIDS,
+ (HAL_UUID_LEN * uuid_count),
+ uuids);
+ ev->num_props++;
+
+ if (size > 2) {
+ DBG("Send Adapter properties changed event to HAL user,"
+ " Num Prop [%d] total size [%d]", ev->num_props, size);
+ event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
+ }
+
+ g_variant_iter_free(iter);
+ g_variant_unref(result);
+ g_variant_unref(temp);
+ return FALSE;
+
+fail:
+ ev->status = BT_STATUS_FAIL;
+ ev->num_props = 0;
+ DBG("Send Adapter properties changed event to HAL user,"
+ " Num Prop [%d] total size [%d]", ev->num_props, size);
+ event_cb(HAL_EV_ADAPTER_PROPS_CHANGED, (void*) buf, size);
+
+ g_variant_unref(result);
+ return FALSE;
+}
+
+int _bt_hal_dbus_get_adapter_supported_uuids(void)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *result;
+
+ DBG("+");
+
+ proxy = _bt_get_adapter_properties_proxy();
+
+ if (!proxy) {
+ DBG("_bt_hal_dbus_get_local_name: Adapter Properties proxy get failed!!!");
+ return BT_STATUS_FAIL;
+ }
+
+ result = g_dbus_proxy_call_sync(proxy,
+ "Get",
+ g_variant_new("(ss)", BT_ADAPTER_INTERFACE,
+ "UUIDs"),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (!result) {
+ if (error != NULL) {
+ ERR("Failed to get UUIDs (Error: %s)", error->message);
+ g_clear_error(&error);
+ } else
+ ERR("Failed to get UUIDs");
+ return BT_STATUS_FAIL;
+ }
+
+
+ DBG("Got All Adaptr service UUID's from Bluez Stack!!, time to start parsing");
+
+ /*
+ * As we need to provide async callback to user from HAL, simply schedule a
+ * callback method which will carry actual result
+ */
+ g_idle_add(__bt_adapter_service_uuids_cb, (gpointer)result);
+
+ DBG("-");
+ return BT_STATUS_SUCCESS;
+}
+
int _bt_hal_dbus_get_adapter_property(bt_property_type_t property_type)
{
DBG("+");
case BT_PROPERTY_CLASS_OF_DEVICE:
return BT_STATUS_UNSUPPORTED;
case BT_PROPERTY_UUIDS:
- return BT_STATUS_UNSUPPORTED;
+ return _bt_hal_dbus_get_adapter_supported_uuids();
case BT_PROPERTY_ADAPTER_BONDED_DEVICES:
return BT_STATUS_UNSUPPORTED;
default:
*/
oal_status_t adapter_get_discoverable_timeout(int *p_timeout);
+/**
+ * @brief Get List of UUIDs for services supported
+ *
+ * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+ * @retval #OAL_STATUS_SUCCESS Successful
+ *
+ * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED
+ *
+ * @see OAL_EVENT_ADAPTER_PROPERTY_SERVICES
+ */
+oal_status_t adapter_get_service_uuids(void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
return OAL_STATUS_SUCCESS;
}
+oal_status_t adapter_get_service_uuids(void)
+{
+ int ret;
+
+ CHECK_OAL_INITIALIZED();
+
+ API_TRACE();
+
+ ret = blued_api->get_adapter_property(BT_PROPERTY_UUIDS);
+ if (ret != BT_STATUS_SUCCESS) {
+ BT_ERR("get_adapter_property failed: [%s]", status2string(ret));
+ return convert_to_oal_status(ret);
+ }
+
+ return OAL_STATUS_SUCCESS;
+}
+
static void cb_adapter_properties (bt_status_t status,
int num_properties,
bt_property_t *properties)
return BLUETOOTH_ERROR_NONE;
}
+int _bt_is_service_used(void)
+{
+ int result;
+
+ BT_DBG("+");
+
+ result = adapter_get_service_uuids();
+ if (result != OAL_STATUS_SUCCESS) {
+ BT_ERR("adapter_get_service_uuids failed: %d", result);
+ result = BLUETOOTH_ERROR_INTERNAL;
+ } else {
+ result = BLUETOOTH_ERROR_NONE;
+ }
+
+ BT_DBG("-");
+ return result;
+}
+
static void __bt_adapter_event_handler(int event_type, gpointer event_data)
{
BT_DBG("+");
BT_INFO("Discoverable timeout: [%d]", *timeout);
break;
}
+ case OAL_EVENT_ADAPTER_PROPERTY_SERVICES: {
+ int count;
+ service_uuid_t *service_list;
+ event_adapter_services_t *list = event_data;
+
+ count = list->num;
+ service_list = list->service_list;
+ __bt_adapter_handle_pending_requests(BT_IS_SERVICE_USED, service_list, count);
+ break;
+ }
default:
BT_ERR("Unhandled event..");
break;
case BT_GET_LOCAL_VERSION:
g_array_append_vals(out_param, user_data, size);
break;
+ case BT_IS_SERVICE_USED: {
+ int i;
+ gboolean used = FALSE;
+ unsigned char *uuid;
+ char uuid_str[BT_UUID_STRING_SIZE];
+ char *request_uuid = req_info->user_data;
+ service_uuid_t *service_list = user_data;
+
+ BT_INFO("Check for service uuid: %s", request_uuid);
+ for (i = 0; i < size; i++) {
+ uuid = service_list[i].uuid;
+ _bt_service_convert_uuid_type_to_string(uuid_str, uuid);
+ BT_INFO("Adapter Service: [%s]", uuid_str);
+ if (strcasecmp(uuid_str, request_uuid) == 0) {
+ BT_INFO("UUID matched!!");
+ used = TRUE;
+ break;
+ }
+ }
+
+ g_array_append_vals(out_param, &used, sizeof(gboolean));
+ break;
+ }
default:
BT_ERR("Unknown service function[%d]", service_function);
}
g_array_append_vals(*out_param1, &discoverable_mode, sizeof(int));
break;
}
+ case BT_IS_SERVICE_USED: {
+ char *uuid = NULL;
+
+ uuid = (char *)g_variant_get_data(in_param1);
+ BT_INFO("UUID to be searched [%s]", uuid);
+ result = _bt_is_service_used();
+
+ /* Save invocation */
+ if (result == BLUETOOTH_ERROR_NONE) {
+ sender = (char*)g_dbus_method_invocation_get_sender(context);
+ _bt_save_invocation_context(context, result, sender,
+ function_name, (gpointer)uuid);
+ }
+ break;
+ }
default:
BT_INFO("UnSupported function [%d]", function_name);
result = BLUETOOTH_ERROR_NOT_SUPPORT;
}
}
+void _bt_service_convert_uuid_type_to_string(char *str, const unsigned char *uuid)
+{
+ ret_if(str == NULL);
+ ret_if(uuid == NULL);
+
+ g_snprintf(str, BT_UUID_STRING_SIZE,
+ "%2.2X%2.2X%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X-%2.2X%2.2X%2.2X%2.2X%2.2X%2.2X",
+ uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
+ uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
+}
int _bt_get_discoverable_mode(int *mode);
+int _bt_is_service_used(void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#define BT_NODE_NAME_LEN 50
+#define BT_UUID_STRING_SIZE 37
typedef struct {
int req_id;
void _bt_clear_request_list(void);
+void _bt_service_convert_uuid_type_to_string(char *str, const unsigned char *uuid);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */