/*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Hocheol Seo <hocheol.seo@samsung.com>
- * Girishashok Joshi <girish.joshi@samsung.com>
- * Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
*/
#include <stdio.h>
-//#include <dbus/dbus-glib.h>
-//#include <dbus/dbus.h>
+#include <dbus/dbus.h>
#include <gio/gio.h>
#include <glib.h>
#include <dlog.h>
#include <string.h>
#include <vconf.h>
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
#include <syspopup_caller.h>
-#endif
#include <aul.h>
#include "bt-internal-types.h"
#include "bt-service-event.h"
#include "bt-service-adapter.h"
#include "bt-service-adapter-le.h"
+#include "bt-service-util.h"
#define BT_ADV_INTERVAL_MIN 20 /* msec */
#define BT_ADV_FILTER_POLICY_DEFAULT 0x00
#define BT_ADV_TYPE_DEFAULT 0x00
#define BT_ADV_FILTER_POLICY_ALLOW_SCAN_CONN_WL_ONLY 0x03
+#define BT_ADV_MULTI_MAX 16
typedef struct {
int adv_inst_max;
char *sender;
int adv_handle;
gboolean is_advertising;
+ guint hold_timer_id;
} bt_adapter_le_adv_slot_t;
typedef struct {
static gboolean scan_filter_enabled = FALSE;
static bt_le_scan_type_t le_scan_type = BT_LE_PASSIVE_SCAN;
+static GSList *gatt_client_senders = NULL;
+
+
+gboolean _bt_is_set_scan_parameter(void)
+{
+ return is_le_set_scan_parameter;
+}
+
+void _bt_init_gatt_client_senders(void)
+{
+ _bt_clear_request_list();
+}
+
+int _bt_insert_gatt_client_sender(char *sender)
+{
+ char *info;
+
+ retv_if(sender == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
+
+ info = g_strdup(sender);
+ retv_if(info == NULL, BLUETOOTH_ERROR_MEMORY_ALLOCATION);
+
+ gatt_client_senders = g_slist_append(gatt_client_senders, info);
+
+ BT_DBG("insert sender: %s", sender);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_delete_gatt_client_sender(char *sender)
+{
+ GSList *l;
+ char *info;
+
+ BT_DBG("remove sender: %s", sender);
+
+ for (l = gatt_client_senders; l != NULL; l = g_slist_next(l)) {
+ info = l->data;
+ if (info == NULL)
+ continue;
+
+ if (g_strcmp0(info, sender) == 0) {
+ BT_DBG("remove info");
+ gatt_client_senders = g_slist_remove(gatt_client_senders, info);
+ g_free(info);
+ return BLUETOOTH_ERROR_NONE;
+ }
+ }
+
+ return BLUETOOTH_ERROR_NOT_FOUND;
+}
+
+void _bt_clear_gatt_client_senders(void)
+{
+ if (gatt_client_senders) {
+ g_slist_foreach(gatt_client_senders, (GFunc)g_free, NULL);
+ g_slist_free(gatt_client_senders);
+ gatt_client_senders = NULL;
+ }
+}
+#if 0
+static void __bt_send_foreach_event(gpointer data, gpointer user_data)
+{
+ char *sender = data;
+ GVariant *param = user_data;
+
+ _bt_send_event_to_dest(sender, BT_DEVICE_EVENT, BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED,
+ param);
+}
+#endif
+void _bt_send_char_value_changed_event(void *param)
+{
+#if 0
+ g_slist_foreach(gatt_client_senders, __bt_send_foreach_event,
+ (gpointer)param);
+#else
+ _bt_send_event(BT_DEVICE_EVENT, BLUETOOTH_EVENT_GATT_CHAR_VAL_CHANGED, param);
+#endif
+}
+
void __bt_free_le_adv_slot(void)
{
int i;
gboolean _bt_update_le_feature_support(const char *item, const char *value)
{
- if (item== NULL || value == NULL)
+ if (item == NULL || value == NULL)
return FALSE;
if (g_strcmp0(item, "adv_inst_max") == 0) {
- if (atoi(value) != le_feature_info.adv_inst_max) {
+ int slot_num;
+
+ slot_num = atoi(value);
+ retv_if(slot_num < 0, FALSE);
+ retv_if(slot_num > BT_ADV_MULTI_MAX, FALSE);
+
+ if (slot_num != le_feature_info.adv_inst_max) {
__bt_free_le_adv_slot();
- le_feature_info.adv_inst_max = atoi(value);
+ le_feature_info.adv_inst_max = slot_num;
+ BT_INFO("Advertising instance max : %d", le_feature_info.adv_inst_max);
le_adv_slot = g_malloc0(sizeof(bt_adapter_le_adv_slot_t) * le_feature_info.adv_inst_max);
}
} else if (g_strcmp0(item, "rpa_offloading") == 0) {
le_feature_info.rpa_offloading = atoi(value);
+ BT_INFO("RPA offloading : %d", le_feature_info.rpa_offloading);
} else if (g_strcmp0(item, "max_filter") == 0) {
le_feature_info.max_filter = atoi(value);
+ BT_INFO("BLE Scan max filter : %d", le_feature_info.max_filter);
} else {
BT_DBG("No registered item");
return FALSE;
static gboolean __bt_is_factory_test_mode(void)
{
int mode = 0;
-#ifdef ENABLE_TIZEN_2_4
+
if (vconf_get_bool(VCONFKEY_BT_DUT_MODE, &mode)) {
BT_ERR("Get the DUT Mode fail");
return TRUE;
}
-#endif
+
if (mode != FALSE) {
BT_INFO("DUT Test Mode !!");
return TRUE;
{
int i;
- if (le_adv_slot == NULL)
+ if (le_adv_slot == NULL) {
+ BT_ERR("le_adv_slot is NULL");
return -1;
+ }
+
+ BT_DBG("adv_inst_max : %d", le_feature_info.adv_inst_max);
for (i = 0; i < le_feature_info.adv_inst_max; i++) {
if (le_adv_slot[i].sender == NULL)
return -1;
}
-void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_id)
+static void __bt_register_adv_slot_owner(const char *sender, int adv_handle, int slot_id)
{
if (le_adv_slot[slot_id].sender == NULL) {
le_adv_slot[slot_id].sender = strdup(sender);
}
}
-void __bt_unregister_adv_slot_owner(int slot_id)
+void _bt_unregister_adv_slot_owner(int slot_id)
{
g_free(le_adv_slot[slot_id].sender);
le_adv_slot[slot_id].sender = NULL;
if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+ if (le_adv_slot[slot_id].hold_timer_id > 0) {
+ g_source_remove(le_adv_slot[slot_id].hold_timer_id);
+ le_adv_slot[slot_id].hold_timer_id = 0;
+ }
+
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
if (le_adv_slot[slot_id].sender != NULL && le_adv_slot[slot_id].is_advertising == FALSE && enable == FALSE)
return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+ if (le_adv_slot[slot_id].hold_timer_id > 0) {
+ g_source_remove(le_adv_slot[slot_id].hold_timer_id);
+ le_adv_slot[slot_id].hold_timer_id = 0;
+ }
+
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
adv_params.interval_min = params->interval_min;
adv_params.interval_max = params->interval_max;
adv_params.filter_policy = params->filter_policy;
- adv_params.type= params->type;
+ adv_params.type = params->type;
if (ret)
g_variant_unref(ret);
if (enable == TRUE)
__bt_register_adv_slot_owner(sender, adv_handle, slot_id);
else
- __bt_unregister_adv_slot_owner(slot_id);
+ _bt_unregister_adv_slot_owner(slot_id);
le_adv_slot[slot_id].is_advertising = enable;
- BT_INFO_C("Set advertising [%d]", enable);
+ BT_INFO_C("### Set advertising [%d]", enable);
if (ret)
g_variant_unref(ret);
return BLUETOOTH_ERROR_NONE;
}
+static gboolean __bt_hold_current_advertising_timeout_cb(gpointer user_data)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+
+ BT_INFO("Restart advertising stopped by bt-service");
+
+ le_adv_slot[0].hold_timer_id = 0;
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, FALSE);
+
+ ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
+ g_variant_new("(bi)", TRUE, 0),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error) {
+ BT_ERR("SetAdvertising Fail: %s", error->message);
+ g_clear_error(&error);
+ return FALSE;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ return FALSE;
+}
+
+int _bt_hold_current_advertising(void)
+{
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+
+ if (le_adv_slot[0].sender && le_adv_slot[0].is_advertising == TRUE) {
+ BT_INFO("Stop current advertising by bt-service");
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ ret = g_dbus_proxy_call_sync(proxy, "SetAdvertising",
+ g_variant_new("(bi)", FALSE, 0),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ if (error) {
+ BT_ERR("SetAdvertising Fail: %s", error->message);
+ g_clear_error(&error);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ if (ret)
+ g_variant_unref(ret);
+
+ le_adv_slot[0].hold_timer_id = g_timeout_add(2000,
+ __bt_hold_current_advertising_timeout_cb, NULL);
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
static int __bt_get_ad_data_by_type(char *in_data, int in_len,
char in_type, char **data, int *data_len)
{
bt_adapter_le_scanner_t *scanner;
GSList *fl;
bluetooth_le_scan_filter_t *filter_data;
- gboolean *slot_check_list;
+ gboolean *slot_check_list = NULL;
int i;
if (le_feature_info.max_filter == 0) {
return -1;
}
slot_check_list = g_malloc0(sizeof(gboolean) * le_feature_info.max_filter);
+ if (slot_check_list == NULL) {
+ BT_ERR("Fail to allocate memory");
+ return -1;
+ }
for (l = scanner_list; l != NULL; l = g_slist_next(l)) {
scanner = l->data;
return -1;
}
+gboolean _bt_is_scan_filter_supported(void)
+{
+ if (le_feature_info.max_filter > 0) {
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *filter, int *slot_id)
{
GDBusProxy *proxy;
GError *error = NULL;
GVariant *ret, *param;
- GVariant *arr_uuid_param, *arr_uuid_mask_param;
- GVariant *arr_data_param, *arr_data_mask_param;
- GArray *arr_uuid;
- GArray *arr_uuid_mask;
- GArray *arr_data;
- GArray *arr_data_mask;
+ GVariant *arr_uuid_param = NULL, *arr_uuid_mask_param = NULL;
+ GVariant *arr_data_param = NULL, *arr_data_mask_param = NULL;
+ GArray *arr_uuid = NULL;
+ GArray *arr_uuid_mask = NULL;
+ GArray *arr_data = NULL;
+ GArray *arr_data_mask = NULL;
bt_adapter_le_scanner_t *scanner = NULL;
bluetooth_le_scan_filter_t *filter_data = NULL;
int feature_selection = 0;
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
- arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
- arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
- arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
- arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
-
- arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->service_uuid.data_len * sizeof(guint8), TRUE, NULL, NULL);
- arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid_mask, filter->service_uuid_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
- arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_data, filter->service_data.data_len * sizeof(guint8), TRUE, NULL, NULL);
- arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_data_mask, filter->service_data_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
-
if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS) {
char address[BT_ADDRESS_STRING_SIZE] = { 0 };
feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS;
_bt_convert_addr_type_to_string(address, filter->device_address.addr);
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+
param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
0, // client_if
0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_ADDRESS, // filter_type
- slot_id, // filter_index
+ *slot_id, // filter_index
0, // company_id
0, // company_id_mask
arr_uuid_param, // p_uuid
if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME) {
feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME;
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+
param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
0, // client_if
0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME, // filter_type
- slot_id, // filter_index
+ *slot_id, // filter_index
0, // company_id
0, // company_id_mask
arr_uuid_param, // p_uuid
if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID) {
feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID;
+ arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
g_array_append_vals(arr_uuid, filter->service_uuid.data.data, filter->service_uuid.data_len * sizeof(guint8));
g_array_append_vals(arr_uuid_mask, filter->service_uuid_mask.data.data, filter->service_uuid_mask.data_len * sizeof(guint8));
arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->service_uuid.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->service_uuid_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
0, // client_if
0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_UUID, // filter_type
- slot_id, // filter_index
+ *slot_id, // filter_index
0, // company_id
0, // company_id_mask
arr_uuid_param, // p_uuid
}
if (ret)
g_variant_unref(ret);
+
+ g_array_free(arr_uuid, TRUE);
+ g_array_free(arr_uuid_mask, TRUE);
+ g_array_free(arr_data, TRUE);
+ g_array_free(arr_data_mask, TRUE);
}
if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID) {
feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID;
+ arr_uuid = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_uuid_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
g_array_append_vals(arr_uuid, filter->service_solicitation_uuid.data.data, filter->service_solicitation_uuid.data_len * sizeof(guint8));
g_array_append_vals(arr_uuid_mask, filter->service_solicitation_uuid_mask.data.data, filter->service_solicitation_uuid_mask.data_len * sizeof(guint8));
arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->service_solicitation_uuid.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_uuid->data, arr_uuid->len, TRUE, NULL, NULL);
arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->service_solicitation_uuid_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_uuid_mask->data, arr_uuid_mask->len, TRUE, NULL, NULL);
+ arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
0, // client_if
0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_SOLICITATION_UUID, // filter_type
- slot_id, // filter_index
+ *slot_id, // filter_index
0, // company_id
0, // company_id_mask
arr_uuid_param, // p_uuid
}
if (ret)
g_variant_unref(ret);
+
+ g_array_free(arr_uuid, TRUE);
+ g_array_free(arr_uuid_mask, TRUE);
}
if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA) {
feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA;
+ arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
g_array_append_vals(arr_data, filter->service_data.data.data, filter->service_data.data_len * sizeof(guint8));
g_array_append_vals(arr_data_mask, filter->service_data_mask.data.data, filter->service_data_mask.data_len * sizeof(guint8));
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->service_data.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_data->data, arr_data->len, TRUE, NULL, NULL);
arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->service_data_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
0, // client_if
0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA, // filter_type
- slot_id, // filter_index
+ *slot_id, // filter_index
0, // company_id
0, // company_id_mask
arr_uuid_param, // p_uuid
}
if (ret)
g_variant_unref(ret);
+
+ g_array_free(arr_data, TRUE);
+ g_array_free(arr_data_mask, TRUE);
}
if (filter->added_features & BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA) {
feature_selection |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA;
+ arr_data = g_array_new(TRUE, TRUE, sizeof(guint8));
+ arr_data_mask = g_array_new(TRUE, TRUE, sizeof(guint8));
+
g_array_append_vals(arr_data, filter->manufacturer_data.data.data, filter->manufacturer_data.data_len * sizeof(guint8));
g_array_append_vals(arr_data_mask, filter->manufacturer_data_mask.data.data, filter->manufacturer_data_mask.data_len * sizeof(guint8));
+ arr_uuid_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
+ arr_uuid_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
+ NULL, 0, TRUE, NULL, NULL);
arr_data_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->manufacturer_data.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_data->data, arr_data->len, TRUE, NULL, NULL);
arr_data_mask_param = g_variant_new_from_data((const GVariantType *)"ay",
- arr_uuid, filter->manufacturer_data_mask.data_len * sizeof(guint8), TRUE, NULL, NULL);
+ arr_data_mask->data, arr_data_mask->len, TRUE, NULL, NULL);
param = g_variant_new("(iiiiii@ay@aysu@ay@ay)",
0, // client_if
0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA, // filter_type
- slot_id, // filter_index
+ *slot_id, // filter_index
filter->manufacturer_id, // company_id
0xFFFF, // company_id_mask
arr_uuid_param, // p_uuid
}
if (ret)
g_variant_unref(ret);
- }
- g_array_free(arr_uuid, TRUE);
- g_array_free(arr_uuid_mask, TRUE);
- g_array_free(arr_data, TRUE);
- g_array_free(arr_data_mask, TRUE);
+ g_array_free(arr_data, TRUE);
+ g_array_free(arr_data_mask, TRUE);
+ }
BT_DBG("Filter selection %.2x", feature_selection);
param = g_variant_new("(iiiiiiiiiiii)",
0, // client_if
0, // action (Add - 0x00, Delete - 0x01, Clear - 0x02)
- slot_id, // filter_index
+ *slot_id, // filter_index
feature_selection, // feat_seln
0, // list_logic_type (OR - 0x00, AND - 0x01)
1, // filt_logic_type (OR - 0x00, AND - 0x01)
scanner = __bt_find_scanner_from_list(sender);
if (scanner == NULL) {
scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
- scanner->sender = strdup(sender);
- scanner_list = g_slist_append(scanner_list, scanner);
+ if (scanner) {
+ scanner->sender = strdup(sender);
+ scanner_list = g_slist_append(scanner_list, scanner);
+ }
}
filter_data = g_malloc0(sizeof(bluetooth_le_scan_filter_t));
- memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t));
- filter_data->slot_id = *slot_id;
+ if (filter_data) {
+ memcpy(filter_data, filter, sizeof(bluetooth_le_scan_filter_t));
+ filter_data->slot_id = *slot_id;
- scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
+ if (scanner)
+ scanner->filter_list = g_slist_append(scanner->filter_list, filter_data);
+ }
if (ret)
g_variant_unref(ret);
if (scanner == NULL) {
scanner = g_malloc0(sizeof(bt_adapter_le_scanner_t));
+ retv_if(scanner == NULL, BLUETOOTH_ERROR_INTERNAL);
+
scanner->sender = strdup(sender);
scanner_list = g_slist_append(scanner_list, scanner);
}
BT_ERR("BT is already in LE scanning");
return BLUETOOTH_ERROR_IN_PROGRESS;
}
+ scanner->is_scanning = TRUE;
proxy = _bt_get_adapter_proxy();
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
} else {
BT_INFO("LE Full Scan is already on progress");
}
-
- scanner->is_scanning = TRUE;
return BLUETOOTH_ERROR_NONE;
} else {
if (is_le_set_scan_parameter == FALSE) {
/* Set default scan parameter same with BT_ADAPTER_LE_SCAN_MODE_LOW_ENERGY */
bluetooth_le_scan_params_t scan_params;
- scan_params.type = 1;
+ scan_params.type = BT_LE_ACTIVE_SCAN;
scan_params.interval = 5000;
scan_params.window = 500;
_bt_set_scan_parameters(&scan_params);
}
ret = g_dbus_proxy_call_sync(proxy, "StartLEDiscovery",
- NULL,G_DBUS_CALL_FLAGS_NONE,
+ NULL, G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
if (error) {
if (ret)
g_variant_unref(ret);
-
- scanner->is_scanning = TRUE;
return BLUETOOTH_ERROR_NONE;
}
}
ret = g_dbus_proxy_call_sync(proxy, "StopLEDiscovery",
- NULL,G_DBUS_CALL_FLAGS_NONE,
+ NULL, G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
if (ret == NULL) {
BT_ERR("LE Scan stop failed");
__bt_get_ad_data_by_type((char*)adv_data, adv_data_len,
ad_type, &data, &data_len);
if (data != NULL) {
- _bt_swap_byte_ordering(data, data_len);
for (i = 0; i < data_len; i += uuid_len) {
if (uuid_len > (data_len - i))
break;
adv_data_len,
BT_LE_AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
&data, &data_len);
+
if (data != NULL) {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- if (_bt_byte_arr_cmp_with_mask(data,
- (char*)filter_data->manufacturer_data.data.data,
- (char*)filter_data->manufacturer_data_mask.data.data,
- data_len) == 0) {
- is_matched = TRUE;
+ int manufacturer_id;
+ manufacturer_id = (data[1] << 8) + data[0];
+
+ if (filter_data->manufacturer_id == manufacturer_id) {
+ if (filter_data->manufacturer_data.data_len == 0) {
+ is_matched = TRUE;
+ } else {
+ if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
+ data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
+ if (_bt_byte_arr_cmp_with_mask(data + 2,
+ (char*)filter_data->manufacturer_data.data.data,
+ (char*)filter_data->manufacturer_data_mask.data.data,
+ data_len - 2) == 0) {
+ is_matched = TRUE;
+ }
+ }
}
g_free(data);
data = NULL;
scan_data_len,
BT_LE_AD_TYPE_MANUFACTURER_SPECIFIC_DATA,
&data, &data_len);
+
if (data != NULL) {
- if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
- data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
- if (_bt_byte_arr_cmp_with_mask(data,
- (char*)filter_data->manufacturer_data.data.data,
- (char*)filter_data->manufacturer_data_mask.data.data,
- data_len) == 0) {
- is_matched = TRUE;
+ int manufacturer_id;
+ manufacturer_id = (data[1] << 8) + data[0];
+
+ if (filter_data->manufacturer_id == manufacturer_id) {
+ if (filter_data->manufacturer_data.data_len == 0) {
+ is_matched = TRUE;
+ } else {
+ if (data_len >= BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX)
+ data_len = BLUETOOTH_ADVERTISING_DATA_LENGTH_MAX - 1;
+ if (_bt_byte_arr_cmp_with_mask(data + 2,
+ (char*)filter_data->manufacturer_data.data.data,
+ (char*)filter_data->manufacturer_data_mask.data.data,
+ data_len - 2) == 0) {
+ is_matched = TRUE;
+ }
+ }
}
g_free(data);
data = NULL;
scan_data_len,
scan_data_param);
+#if 0
_bt_send_event_to_dest(scanner->sender, BT_LE_ADAPTER_EVENT,
BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, param);
+#else
+ _bt_send_event(BT_LE_ADAPTER_EVENT, BLUETOOTH_EVENT_REMOTE_LE_DEVICE_FOUND, param);
+#endif
}
}
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
ret = g_dbus_proxy_call_sync(proxy, "ClearDeviceWhiteList",
- NULL,G_DBUS_CALL_FLAGS_NONE,
+ NULL, G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
if (error) {
return BLUETOOTH_ERROR_NONE;
}
+int _bt_initialize_ipsp(void)
+{
+ BT_DBG("+");
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+
+ if (_bt_adapter_get_status() != BT_ACTIVATED &&
+ _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ ret = g_dbus_proxy_call_sync(proxy, "InitializeIpsp",
+ NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (error) {
+ BT_ERR("Initialize IPSP Failed :[%s]", error->message);
+ g_clear_error(&error);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ if (ret)
+ g_variant_unref(ret);
+
+ BT_INFO("IPSP initialization called successfully");
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_deinitialize_ipsp(void)
+{
+ BT_DBG("+");
+ GDBusProxy *proxy;
+ GError *error = NULL;
+ GVariant *ret;
+
+ if (_bt_adapter_get_status() != BT_ACTIVATED &&
+ _bt_adapter_get_le_status() != BT_LE_ACTIVATED) {
+ return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED;
+ }
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ ret = g_dbus_proxy_call_sync(proxy, "DeinitializeIpsp",
+ NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (error) {
+ BT_ERR("De-Initialize IPSP Failed :[%s]", error->message);
+ g_clear_error(&error);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+ if (ret)
+ g_variant_unref(ret);
+
+ BT_INFO("IPSP De-initialization called successfully");
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_le_read_maximum_data_length(
+ bluetooth_le_read_maximum_data_length_t *max_le_datalength)
+{
+ GError *error = NULL;
+ GDBusProxy *proxy;
+ GVariant *reply = NULL;
+ guint16 max_tx_octets, max_tx_time;
+ guint16 max_rx_octets, max_rx_time;
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ reply = g_dbus_proxy_call_sync(proxy, "LEReadMaximumDataLength",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("LEReadMaximumDataLength dBUS-RPC failed");
+ if (error != NULL) {
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_variant_get(reply, "(qqqq)", &max_tx_octets, &max_tx_time,
+ &max_rx_octets, &max_rx_time);
+
+ max_le_datalength->max_tx_octets = max_tx_octets;
+ max_le_datalength->max_tx_time = max_tx_time;
+ max_le_datalength->max_rx_octets = max_rx_octets;
+ max_le_datalength->max_rx_time = max_rx_time;
+
+ g_variant_unref(reply);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+int _bt_le_write_host_suggested_default_data_length(
+ const unsigned int def_tx_Octets, const unsigned int def_tx_Time)
+{
+ GError *error = NULL;
+ GDBusProxy *proxy;
+ GVariant *reply = NULL;
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ reply = g_dbus_proxy_call_sync(proxy,
+ "LEWriteHostSuggestedDataLength",
+ g_variant_new("(qq)", def_tx_Octets, def_tx_Time),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ g_object_unref(proxy);
+
+ if (reply == NULL) {
+ BT_ERR("_bt_le_write_host_suggested_default_data_length dBUS-RPC failed");
+ if (error != NULL) {
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_variant_unref(reply);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_le_read_host_suggested_default_data_length(
+ bluetooth_le_read_host_suggested_data_length_t *def_data_length)
+{
+ GError *error = NULL;
+ GDBusProxy *proxy;
+ GVariant *reply = NULL;
+ guint16 def_tx_octets, def_tx_time;
+
+ proxy = _bt_get_adapter_proxy();
+ retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ reply = g_dbus_proxy_call_sync(proxy, "LEReadHostSuggestedDataLength",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
+
+ if (reply == NULL) {
+ BT_ERR("LEReadHostSuggestedDataLength dBUS-RPC failed");
+ if (error != NULL) {
+ BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+ error->code, error->message);
+ g_clear_error(&error);
+ }
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ g_variant_get(reply, "(qq)", &def_tx_octets, &def_tx_time);
+
+ def_data_length->def_tx_octets = def_tx_octets;
+ def_data_length->def_tx_time = def_tx_time;
+
+ g_variant_unref(reply);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_le_set_data_length(bluetooth_device_address_t *device_address,
+ const unsigned int max_tx_Octets, const unsigned int max_tx_Time)
+{
+ GError *error = NULL;
+ guint16 txOctets = max_tx_Octets;
+ guint16 txTime = max_tx_Time;
+ char address[BT_ADDRESS_STRING_SIZE] = { 0 };
+ gchar *device_path = NULL;
+ GDBusConnection *conn;
+ GDBusProxy *device_proxy;
+
+ _bt_convert_addr_type_to_string(address, device_address->addr);
+
+ device_path = _bt_get_device_object_path(address);
+
+ if (device_path == NULL) {
+ BT_DBG("Device path is null");
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ conn = _bt_get_system_gconn();
+ if (conn == NULL) {
+ BT_ERR("conn == NULL");
+ g_free(device_path);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ device_proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+ NULL, BT_BLUEZ_NAME,
+ device_path, BT_DEVICE_INTERFACE, NULL, NULL);
+
+ g_free(device_path);
+ retv_if(device_proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
+
+ g_dbus_proxy_call_sync(device_proxy,
+ "LESetDataLength",
+ g_variant_new("(qq)", txOctets, txTime),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+
+ g_object_unref(device_proxy);
+
+ if (error) {
+ BT_ERR("LESetDataLength error: [%s]", error->message);
+ g_error_free(error);
+ return BLUETOOTH_ERROR_INTERNAL;
+ }
+
+ return BLUETOOTH_ERROR_NONE;
+}