From e525e8a5f36e697b6c6b06dc6874923ac4ddf561 Mon Sep 17 00:00:00 2001 From: Wootak Jung Date: Fri, 25 Oct 2019 13:25:25 +0900 Subject: [PATCH] Fix le scan start/stop timing issue le scan functionaly is blocked in case stop request is come right after start request is come. le scan started/stopped events depend on LEDiscovering Change-Id: I2531b426b72112c2aa1e21cae897a4b6f75d5343 --- bt-api/bt-adapter-le.c | 3 ++- bt-oal/bluez_hal/inc/bt-hal-msg.h | 3 ++- bt-oal/bluez_hal/src/bt-hal-event-receiver.c | 9 +++++++-- bt-oal/hardware/bluetooth.h | 10 +++++++--- bt-oal/oal-adapter-mgr.c | 14 ++++++++------ bt-oal/oal-gatt.c | 4 +--- .../services/adapter/bt-service-core-adapter-le.c | 12 ++++++------ 7 files changed, 33 insertions(+), 22 deletions(-) diff --git a/bt-api/bt-adapter-le.c b/bt-api/bt-adapter-le.c index 96af979..20b2d31 100644 --- a/bt-api/bt-adapter-le.c +++ b/bt-api/bt-adapter-le.c @@ -129,7 +129,8 @@ BT_EXPORT_API int bluetooth_stop_le_discovery(void) BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - _bt_set_le_scan_status(FALSE); + if (result == BLUETOOTH_ERROR_NONE) + _bt_set_le_scan_status(FALSE); return result; } diff --git a/bt-oal/bluez_hal/inc/bt-hal-msg.h b/bt-oal/bluez_hal/inc/bt-hal-msg.h index 7c5b316..d30aaae 100644 --- a/bt-oal/bluez_hal/inc/bt-hal-msg.h +++ b/bt-oal/bluez_hal/inc/bt-hal-msg.h @@ -77,7 +77,8 @@ struct hal_prop_device_service_rec { #define HAL_PROP_DEVICE_BLE_ADV_DATA 0x17 #define HAL_PROP_ADAPTER_LOCAL_LE_FEAT 0x18 #define HAL_PROP_DEVICE_IS_ALIAS_SET 0x19 -#define HAL_PROP_ADAPTER_LE_DISCOVERY_FINISHED 0x1a +#define HAL_PROP_ADAPTER_LE_DISCOVERY_STARTED 0x1a +#define HAL_PROP_ADAPTER_LE_DISCOVERY_STOPPED 0x1b struct hal_prop_device_info { uint8_t version; diff --git a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c index 68e97e8..2dbfd63 100644 --- a/bt-oal/bluez_hal/src/bt-hal-event-receiver.c +++ b/bt-oal/bluez_hal/src/bt-hal-event-receiver.c @@ -407,8 +407,13 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg) is_le_discovering = g_variant_get_boolean(value); DBG("##LE Discovering = [%d]", is_le_discovering); - if (is_le_discovering) + if (is_le_discovering) { + /* Send LE discovering started event */ + size += __bt_insert_hal_properties(buf + size, + HAL_PROP_ADAPTER_LE_DISCOVERY_STARTED, 0, NULL); + ev->num_props++; continue; + } adapter_proxy = _bt_hal_get_adapter_proxy(); if (adapter_proxy == NULL) { @@ -432,7 +437,7 @@ static void __bt_hal_adapter_property_changed_event(GVariant *msg) /* Send LE discovering finished event */ size += __bt_insert_hal_properties(buf + size, - HAL_PROP_ADAPTER_LE_DISCOVERY_FINISHED, sizeof(gboolean), &is_le_discovering); + HAL_PROP_ADAPTER_LE_DISCOVERY_STOPPED, 0, NULL); ev->num_props++; } else if (!g_strcmp0(key, "Modalias")) { char *modalias = NULL; diff --git a/bt-oal/hardware/bluetooth.h b/bt-oal/hardware/bluetooth.h index 4270e22..088a105 100644 --- a/bt-oal/hardware/bluetooth.h +++ b/bt-oal/hardware/bluetooth.h @@ -376,10 +376,14 @@ typedef enum { BT_PROPERTY_REMOTE_IS_ALIAS_SET, /** - * Description - Bluetooth Adapter LE Discovery finished - * Data type - gboolean + * Description - Bluetooth Adapter LE Discovery started */ - BT_PROPERTY_ADAPTER_LE_DISCOVERY_FINISHED, + BT_PROPERTY_ADAPTER_LE_DISCOVERY_STARTED, + + /** + * Description - Bluetooth Adapter LE Discovery stopped + */ + BT_PROPERTY_ADAPTER_LE_DISCOVERY_STOPPED, BT_PROPERTY_REMOTE_DEVICE_TIMESTAMP = 0xFF, } bt_property_type_t; diff --git a/bt-oal/oal-adapter-mgr.c b/bt-oal/oal-adapter-mgr.c index 56af6d1..65e6abd 100644 --- a/bt-oal/oal-adapter-mgr.c +++ b/bt-oal/oal-adapter-mgr.c @@ -951,12 +951,14 @@ static void cb_adapter_properties(bt_status_t status, sizeof(event_adapter_le_features_t)); break; } - case BT_PROPERTY_ADAPTER_LE_DISCOVERY_FINISHED: { - gboolean le_discovering = *(gboolean *)properties[i].val; - if (le_discovering == FALSE) { - BT_INFO("LE Discovery finished"); - send_event(OAL_EVENT_BLE_DISCOVERY_FINISHED, NULL, 0); - } + case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STARTED: { + BT_INFO("LE Discovery started"); + send_event(OAL_EVENT_BLE_DISCOVERY_STARTED, NULL, 0); + break; + } + case BT_PROPERTY_ADAPTER_LE_DISCOVERY_STOPPED: { + BT_INFO("LE Discovery stopped"); + send_event(OAL_EVENT_BLE_DISCOVERY_STOPPED, NULL, 0); break; } default: diff --git a/bt-oal/oal-gatt.c b/bt-oal/oal-gatt.c index ce183c2..9af37b9 100644 --- a/bt-oal/oal-gatt.c +++ b/bt-oal/oal-gatt.c @@ -1741,7 +1741,6 @@ oal_status_t gattc_start_le_discovery(int client_id) BT_ERR("Error:Start LE Discovery failed: %s", status2string(ret)); return convert_to_oal_status(ret); } - send_event(OAL_EVENT_BLE_DISCOVERY_STARTED, NULL, 0); return OAL_STATUS_SUCCESS; } @@ -1757,8 +1756,7 @@ oal_status_t gattc_stop_le_discovery(int client_id) if (ret != BT_STATUS_SUCCESS) { BT_ERR("Error:Stop LE Discovery failed: %s", status2string(ret)); return convert_to_oal_status(ret); - } else - send_event(OAL_EVENT_BLE_DISCOVERY_STOPPED, NULL, 0); + } return OAL_STATUS_SUCCESS; } diff --git a/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c b/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c index aea178a..6c3ab7a 100644 --- a/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c +++ b/bt-service-adaptation/services/adapter/bt-service-core-adapter-le.c @@ -220,9 +220,9 @@ static void __bt_le_update_bt_disabled(void) g_variant_new("(i)", result)); } - static void __bt_set_le_scan_status(gboolean mode) { + BT_DBG("Set scanning status: %s", mode == TRUE ? "TRUE" : "FALSE"); is_le_scanning = mode; } @@ -666,7 +666,6 @@ static void __bt_le_event_handler(int event_type, gpointer event_data) } case OAL_EVENT_BLE_DISCOVERY_STARTED: { __bt_set_le_scan_status(TRUE); - __bt_adapter_le_handle_pending_request_info( BLUETOOTH_ERROR_NONE, BT_START_LE_DISCOVERY, NULL, 0); @@ -682,6 +681,7 @@ static void __bt_le_event_handler(int event_type, gpointer event_data) } __bt_set_le_scan_status(FALSE); + _bt_disable_all_scanner_status(); __bt_adapter_le_handle_pending_request_info( BLUETOOTH_ERROR_NONE, BT_STOP_LE_DISCOVERY, NULL, 0); @@ -727,10 +727,6 @@ static void __bt_le_event_handler(int event_type, gpointer event_data) break; } - case OAL_EVENT_BLE_DISCOVERY_FINISHED: { - _bt_disable_all_scanner_status(); - break; - } default: break; } @@ -1621,17 +1617,20 @@ int _bt_start_le_scan(const char *sender) scanner_list = g_slist_append(scanner_list, scanner); } + /* Check scanning is finished or not */ if (scanner->stop_pending == TRUE) { BT_DBG("Waiting LEDiscoveryFinished"); g_timeout_add(500, (GSourceFunc)__start_le_scan_timeout, scanner->sender); return BLUETOOTH_ERROR_NONE; } + /* Check scanning is in progress or not */ if (scanner->is_scanning) { BT_ERR("BT is already in LE scanning"); return BLUETOOTH_ERROR_IN_PROGRESS; } + /* Check scanning is in progress or not by other users */ if (_bt_is_le_scanning()) { int value = 1; @@ -1673,6 +1672,7 @@ int _bt_stop_le_scan(const char *sender) GSList *l; int ret; + /* Check scanning is in progress or not */ scan_sender = __bt_find_scanner_from_list(sender); if (scan_sender == NULL || scan_sender->is_scanning == FALSE) return BLUETOOTH_ERROR_NOT_IN_OPERATION; -- 2.7.4