#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"
#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 {
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,
+ _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
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);
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 (enable == TRUE)
- _bt_register_adv_slot_owner(sender, adv_handle, slot_id);
+ __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
le_adv_slot[slot_id].is_advertising = enable;
BT_INFO("Set advertising [%d]", enable);
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);
+ __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
else
_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;
}
return BLUETOOTH_ERROR_INTERNAL;
}
- _bt_register_adv_slot_owner(sender, adv_handle, slot_id);
+ __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
__bt_get_ad_data_by_type((char *)adv_data.data, adv_data_len, 0xff,
&old_mdata, &old_len);
return BLUETOOTH_ERROR_INTERNAL;
}
- _bt_register_adv_slot_owner(sender, adv_handle, slot_id);
+ __bt_register_adv_slot_owner(sender, adv_handle, slot_id);
/* Compare with previous scan resp data */
__bt_get_ad_data_by_type((char *)resp_data.data, resp_data_len, 0xff,
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;
}
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) {
}
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;
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) {
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
ret = g_dbus_proxy_call_sync(proxy, "InitializeIpsp",
- NULL,G_DBUS_CALL_FLAGS_NONE,
+ NULL, G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
if (error) {
BT_ERR("Initialize IPSP Failed :[%s]", error->message);
retv_if(proxy == NULL, BLUETOOTH_ERROR_INTERNAL);
ret = g_dbus_proxy_call_sync(proxy, "DeinitializeIpsp",
- NULL,G_DBUS_CALL_FLAGS_NONE,
+ NULL, G_DBUS_CALL_FLAGS_NONE,
-1, NULL, &error);
if (error) {
BT_ERR("De-Initialize IPSP Failed :[%s]", error->message);
return BLUETOOTH_ERROR_INTERNAL;
}
- g_variant_get(reply ,"(qqqq)", &max_tx_octets, &max_tx_time,
+ 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;
return BLUETOOTH_ERROR_INTERNAL;
}
- g_variant_get(reply ,"(qq)", &def_tx_octets, &def_tx_time);
+ 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;