From 7750a92c80c0f35db7ce500828742a3c2b8fb60a Mon Sep 17 00:00:00 2001 From: Ayush Garg Date: Thu, 29 Oct 2020 16:51:29 +0530 Subject: [PATCH] Implement RSSI scan filter Change-Id: I7a443de481083328dc691c252188092a5559871d Signed-off-by: ayushgrg04 --- bt-oal/include/oal-gatt.h | 2 ++ bt-oal/oal-gatt.c | 4 ++++ bt-service/services/adapter/bt-service-core-adapter-le.c | 14 +++++++++++--- include/bluetooth-api.h | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/bt-oal/include/oal-gatt.h b/bt-oal/include/oal-gatt.h index 6f9f7c4..22cc4ce 100644 --- a/bt-oal/include/oal-gatt.h +++ b/bt-oal/include/oal-gatt.h @@ -50,6 +50,7 @@ typedef enum { OAL_BLE_SCAN_FILTER_FEATURE_DEVICE_NAME = 0x10, /**< device name */ OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA = 0x20, /**< manufacturer data */ OAL_BLE_SCAN_FILTER_FEATURE_SERVICE_DATA = 0x40, /**< service data */ + OAL_BLE_SCAN_FILTER_FEATURE_RSSI_HIGH_THRESHOLD = 0x80, /**< rssi high threshold */ } oal_ble_scan_filter_feature_t; /** GATT value type used in response to remote read requests */ @@ -114,6 +115,7 @@ typedef struct { int manufacturer_data_len; uint8_t* manufacturer_data_mask; int manufacturer_data_mask_len; + int rssi_high_threshold; } oal_ble_scan_filter_t; typedef struct { diff --git a/bt-oal/oal-gatt.c b/bt-oal/oal-gatt.c index 905f9ba..9445cf2 100644 --- a/bt-oal/oal-gatt.c +++ b/bt-oal/oal-gatt.c @@ -2374,6 +2374,10 @@ oal_status_t gattc_register_scan_filter(oal_ble_scan_filter_t* filter_data) feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA; } + if (filter_data->added_features & OAL_BLE_SCAN_FILTER_FEATURE_RSSI_HIGH_THRESHOLD) { + scan_filter_setup.rssi_high_thres = filter_data->rssi_high_threshold; + feature_selection |= OAL_BLE_SCAN_FILTER_FEATURE_RSSI_HIGH_THRESHOLD; + } BT_DBG("Filter selection 0x%.2x", feature_selection); diff --git a/bt-service/services/adapter/bt-service-core-adapter-le.c b/bt-service/services/adapter/bt-service-core-adapter-le.c index c2a9748..d16e6ae 100644 --- a/bt-service/services/adapter/bt-service-core-adapter-le.c +++ b/bt-service/services/adapter/bt-service-core-adapter-le.c @@ -618,7 +618,7 @@ static gboolean __bt_check_scan_result_uuid(const char *adv_data, return FALSE; } -static gboolean __bt_check_scan_result_with_filter(const char *device_address, +static gboolean __bt_check_scan_result_with_filter(const char *device_address, int rssi, const char *adv_data, int adv_data_len, const char *scan_data, int scan_data_len, const bt_adapter_le_scanner_t *scanner) @@ -890,6 +890,13 @@ static gboolean __bt_check_scan_result_with_filter(const char *device_address, continue; } + /* Check RSSI filter */ + if (filter_data->added_features & + BLUETOOTH_LE_SCAN_FILTER_FEATURE_RSSI_HIGH_THRESHOLD) { + if (rssi < filter_data->rssi_high_threshold) + continue; + } + BT_INFO("The scan result is conformable."); return TRUE; } @@ -932,7 +939,7 @@ static void __bt_le_handle_device_found(event_ble_scan_result_info *scan_result) if (scanner->is_scanning == FALSE) continue; - if (__bt_check_scan_result_with_filter(address, (const char *)adv_ind_data, + if (__bt_check_scan_result_with_filter(address, scan_result->rssi, (const char *)adv_ind_data, adv_ind_len, (const char *)scan_resp_data, scan_resp_len, scanner) == FALSE) continue; @@ -1989,7 +1996,8 @@ int _bt_register_scan_filter(const char *sender, bluetooth_le_scan_filter_t *fil .service_data_mask = filter->service_data_mask.data.data, .service_data_mask_len = filter->service_data_mask.data_len, .manufacturer_id = filter->manufacturer_id, .manufacturer_data = filter->manufacturer_data.data.data, .manufacturer_data_len = filter->manufacturer_data.data_len, .manufacturer_data_mask = filter->manufacturer_data_mask.data.data, - .manufacturer_data_mask_len = filter->manufacturer_data_mask.data_len , .added_features = filter->added_features + .manufacturer_data_mask_len = filter->manufacturer_data_mask.data_len , .added_features = filter->added_features, + .rssi_high_threshold = filter->rssi_high_threshold }; ret = gattc_register_scan_filter(&filter_data); diff --git a/include/bluetooth-api.h b/include/bluetooth-api.h index 47aa397..273835a 100644 --- a/include/bluetooth-api.h +++ b/include/bluetooth-api.h @@ -1229,6 +1229,7 @@ typedef enum { BLUETOOTH_LE_SCAN_FILTER_FEATURE_DEVICE_NAME = 0x10, /**< device name */ BLUETOOTH_LE_SCAN_FILTER_FEATURE_MANUFACTURER_DATA = 0x20, /**< manufacturer data */ BLUETOOTH_LE_SCAN_FILTER_FEATURE_SERVICE_DATA = 0x40, /**< service data */ + BLUETOOTH_LE_SCAN_FILTER_FEATURE_RSSI_HIGH_THRESHOLD = 0x80, /**< rssi high threshold */ } bluetooth_le_scan_filter_feature_t; /** @@ -1288,6 +1289,7 @@ typedef struct { int manufacturer_id; /**< manufacturer ID */ bluetooth_le_advertising_data_t manufacturer_data; /**< manufacturer data */ bluetooth_le_advertising_data_t manufacturer_data_mask; /**< manufacturer data mask */ + int rssi_high_threshold; /**< rssi high threshold */ } bluetooth_le_scan_filter_t; typedef struct { -- 2.7.4