From: Ayush Garg Date: Fri, 30 Oct 2020 10:06:41 +0000 (+0530) Subject: Implement RSSI scan filter X-Git-Tag: submit/tizen/20201102.065935^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=84e55d5c5473a04881c80baf64a4b9fdc96f399e;p=platform%2Fcore%2Fapi%2Fbluetooth.git Implement RSSI scan filter Change-Id: Ic4d4256f1a21d116fd3c7d9557f5983922d5f6e6 Signed-off-by: ayushgrg04 --- diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index cae4ecd..7a36318 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -898,6 +898,26 @@ int bt_adapter_le_unset_state_changed_cb(void); */ int bt_adapter_le_set_scan_type(bt_adapter_le_scan_type_e scan_type); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Sets the RSSI for the advertisements filter. + * @details Advertiser will be reported only if the signal is higher than specified rssi. + * @since_tizen 6.0 + * + * @param[in] scan_filter The scan filter handle + * @param[in] rssi The RSSI signal which advertisements will be filtered + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + */ +int bt_adapter_le_scan_filter_set_rssi_high_threshold(bt_scan_filter_h scan_filter, int rssi); + /** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index 4192ee6..8bf6212 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -336,6 +336,7 @@ typedef struct { char *manufacturer_data; unsigned int manufacturer_data_len; char *manufacturer_data_mask; + int rssi_high_threshold; } bt_le_scan_filter_s; /** diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index 16e3fb5..5ff36a5 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -2928,6 +2928,11 @@ static void __bt_adapter_le_convert_scan_filter( 0xFF, src->manufacturer_data_len); } } + + if (src->rssi_high_threshold < 0) { + dest->added_features |= BLUETOOTH_LE_SCAN_FILTER_FEATURE_RSSI_HIGH_THRESHOLD; + dest->rssi_high_threshold = src->rssi_high_threshold; + } } static bt_le_scan_filter_s *__bt_adapter_le_duplicate_scan_filter( @@ -2950,6 +2955,7 @@ static bt_le_scan_filter_s *__bt_adapter_le_duplicate_scan_filter( filter->manufacturer_data = g_memdup(src->manufacturer_data, src->manufacturer_data_len); filter->manufacturer_data_len = src->manufacturer_data_len; filter->manufacturer_data_mask = g_memdup(src->manufacturer_data_mask, src->manufacturer_data_len); + filter->rssi_high_threshold = src->rssi_high_threshold; return filter; } @@ -3878,6 +3884,26 @@ int bt_adapter_le_scan_filter_set_manufacturer_data_with_mask(bt_scan_filter_h s return BT_ERROR_NONE; } +int bt_adapter_le_scan_filter_set_rssi_high_threshold(bt_scan_filter_h scan_filter, + int rssi) +{ + bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(scan_filter); + + if (rssi > 0 || rssi < -127) { + BT_ERR("INVALID_PARAMETER(0x%08x)", + BT_ERROR_INVALID_PARAMETER); /* LCOV_EXCL_LINE */ + return BT_ERROR_INVALID_PARAMETER; + } + + __filter->rssi_high_threshold = rssi; + + return BT_ERROR_NONE; +} + int bt_adapter_le_scan_filter_register(bt_scan_filter_h scan_filter) { bt_le_scan_filter_s *__filter = (bt_le_scan_filter_s *)scan_filter; diff --git a/tests/test/bt_unit_test.c b/tests/test/bt_unit_test.c index 8f0bd16..7e8a534 100644 --- a/tests/test/bt_unit_test.c +++ b/tests/test/bt_unit_test.c @@ -350,6 +350,8 @@ tc_table_t tc_adapter_le[] = { , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_MANUFACTURER_DATA}, {"Register iBeaconscan filter (Manufacturer DATA)" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_IBEACON_DATA}, + {"Register scan filter (RSSI)" + , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_RSSI_HIGH_THRES}, {"Unregister all scan filters" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNREGISTER_ALL_SCAN_FILTERS}, {"bt_adater_le_read_maximum_data_length" @@ -3607,6 +3609,7 @@ int test_set_params(int test_id, char *param) break; case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_ADDRESS: case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_NAME: + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_RSSI_HIGH_THRES: param_count = 1; TC_PRT("Input data for LE scan filter"); break; @@ -5454,6 +5457,34 @@ int test_input_callback(void *data) break; } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_RSSI_HIGH_THRES: { + bt_scan_filter_h scan_filter = NULL; + int rssi_high_threshold = -75; + + if (g_test_param.param_count > 0) { + rssi_high_threshold = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_scan_filter_create(&scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_scan_filter_set_rssi_high_threshold(scan_filter, rssi_high_threshold); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_scan_filter_register(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + ret = bt_adapter_le_scan_filter_destroy(scan_filter); + if (ret != BT_ERROR_NONE) + TC_PRT("failed with [0x%04x]", ret); + + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_SOLICITATION_UUID: { bt_scan_filter_h scan_filter; diff --git a/tests/test/bt_unit_test.h b/tests/test/bt_unit_test.h index 5bdc38a..901937d 100644 --- a/tests/test/bt_unit_test.h +++ b/tests/test/bt_unit_test.h @@ -138,6 +138,7 @@ typedef enum { BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_SOLICITATION_UUID, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_MANUFACTURER_DATA, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_IBEACON_DATA, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_RSSI_HIGH_THRES, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNREGISTER_ALL_SCAN_FILTERS, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_DEVICE_DISCOVERY_STATE_CHANGED_CB, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_UNSET_DEVICE_DISCOVERY_STATE_CHANGED_CB,