From: himanshu Date: Thu, 10 Oct 2019 06:22:55 +0000 (+0530) Subject: Port the set manufacturer data functionality into BT-HAL framework. X-Git-Tag: accepted/tizen/unified/20191101.042113~12 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F28%2F215528%2F5;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git Port the set manufacturer data functionality into BT-HAL framework. This API sets the manufacturer-data into the BT-Adapter. The corresponding data change callback will be invoked if data is set successfully. Change-Id: I068a70c0b354a905fcc245ad2e089f4fc3cb06c6 Signed-off-by: himanshu --- diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-le.c b/bt-oal/bluez_hal/src/bt-hal-adapter-le.c index 7852be2..16f8630 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-le.c +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-le.c @@ -1000,6 +1000,54 @@ void _bt_hal_unregister_gatt_le_dbus_handler_cb(void) gatt_le_event_cb = NULL; } +int _bt_hal_adapter_le_set_manufacturer_data(bt_manufacturer_data_t *m_data) +{ + GDBusProxy *proxy; + GError *error = NULL; + int i; + GVariant *val; + GVariant *ret; + GVariantBuilder *builder; + + proxy = _bt_hal_get_adapter_proxy(); + if (proxy == NULL) + return BT_STATUS_FAIL; + + builder = g_variant_builder_new(G_VARIANT_TYPE("ay")); + + if (m_data->data_len + 2 >= BT_MANUFACTURER_DATA_LENGTH_MAX) + return BT_STATUS_PARM_INVALID; + for (i = 0; i < (m_data->data_len) + 2; i++) + g_variant_builder_add(builder, "y", m_data->data[i]); + + val = g_variant_new("(ay)", builder); + + ret = g_dbus_proxy_call_sync(proxy, + "SetManufacturerData", + val, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + &error); + g_variant_builder_unref(builder); + if (!ret) { + if (error != NULL) { + ERR("Failed to SetManufacturerData (Error: %s)", error->message); + g_clear_error(&error); + } else { + ERR("Failed to SetManufacturerData"); + } + return BT_STATUS_FAIL; + } + + INFO("Set manufacturer data"); + g_variant_unref(ret); + + return BT_STATUS_SUCCESS; +} + + + /*add/remove remote device address from white list*/ int _bt_hal_adapter_le_set_white_list(bt_bdaddr_t *device_address, bt_dev_addr_type_t address_type, bool is_add) { diff --git a/bt-oal/bluez_hal/src/bt-hal-adapter-le.h b/bt-oal/bluez_hal/src/bt-hal-adapter-le.h index b84ca20..75da4c5 100644 --- a/bt-oal/bluez_hal/src/bt-hal-adapter-le.h +++ b/bt-oal/bluez_hal/src/bt-hal-adapter-le.h @@ -85,6 +85,8 @@ void _bt_hal_le_deinit(void); int _bt_hal_adapter_le_set_privacy(uint8_t set_privacy); int _bt_hal_adapter_le_set_white_list(bt_bdaddr_t *device_address, bt_dev_addr_type_t address_type, bool is_add); + +int _bt_hal_adapter_le_set_manufacturer_data(bt_manufacturer_data_t *m_data); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c index 1aaa469..bc8fa72 100644 --- a/bt-oal/bluez_hal/src/bt-hal-bluetooth.c +++ b/bt-oal/bluez_hal/src/bt-hal-bluetooth.c @@ -471,6 +471,7 @@ static const bt_interface_t bluetooth_if = { .set_le_static_random_address = _bt_hal_set_le_static_random_address, .set_hal_adapter_request_state = set_hal_adapter_request_state, .set_hal_le_request_state = set_hal_le_request_state, + .adapter_le_set_manufacturer_data = _bt_hal_adapter_le_set_manufacturer_data, .adapter_le_set_white_list = _bt_hal_adapter_le_set_white_list, .adapter_le_set_privacy = _bt_hal_adapter_le_set_privacy, .device_disconnect = dev_disconnect, diff --git a/bt-oal/hardware/bluetooth.h b/bt-oal/hardware/bluetooth.h index fb9d3c3..a377912 100644 --- a/bt-oal/hardware/bluetooth.h +++ b/bt-oal/hardware/bluetooth.h @@ -50,6 +50,7 @@ __BEGIN_DECLS #define BT_PROFILE_GATT_ID "gatt" #define BT_PROFILE_AV_RC_ID "avrcp" #define BT_PROFILE_AV_RC_CTRL_ID "avrcp_ctrl" +#define BT_MANUFACTURER_DATA_LENGTH_MAX 31 /**< This specifies the Maximum manufacturer data Length>*/ /** Bluetooth Address */ typedef struct { @@ -105,6 +106,11 @@ typedef struct { } __attribute__((packed))bt_pin_code_t; typedef struct { + int data_len; /**< manafacturer specific data length */ + char data[BT_MANUFACTURER_DATA_LENGTH_MAX]; +} bt_manufacturer_data_t; + +typedef struct { uint8_t status; uint8_t ctrl_state; /* stack reported state */ uint64_t tx_time; /* in ms */ @@ -886,6 +892,11 @@ typedef struct { * disconnect the device */ int (*device_disconnect)(const bt_bdaddr_t *bd_addr); + + /* + * sets the specified manufacturer data of the adapter + */ + int (*adapter_le_set_manufacturer_data)(bt_manufacturer_data_t *m_data); #endif } bt_interface_t; diff --git a/bt-oal/include/oal-adapter-mgr.h b/bt-oal/include/oal-adapter-mgr.h index 4a4860f..bbe0083 100644 --- a/bt-oal/include/oal-adapter-mgr.h +++ b/bt-oal/include/oal-adapter-mgr.h @@ -474,6 +474,20 @@ oal_status_t adapter_set_white_list(bt_address_t* device_address, int address_ty * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED */ oal_status_t adapter_ble_set_privacy(int set_privacy); + +/** + * @brief set the manufacturer data of the adapter + * + * @param manufacturer data + * + * @details sets the specified manufacturer data in the BT-chip + * + * @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value. + * @retval #OAL_STATUS_SUCCESS Successful + * + * @pre Adapter must be enabled with adapter_enable() followed by OAL_EVENT_ADAPTER_ENABLED + */ +oal_status_t adapter_set_manufacturer_data(oal_manufacturer_data_t* m_data); #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/bt-oal/include/oal-manager.h b/bt-oal/include/oal-manager.h index 387a0cb..ac05875 100755 --- a/bt-oal/include/oal-manager.h +++ b/bt-oal/include/oal-manager.h @@ -44,6 +44,8 @@ extern "C" { #define BLUETOOTH_UUID_STRING_MAX 50 +#define BT_DEVICE_MANUFACTURER_DATA_LEN_MAX 31 /***/ + typedef void (*oal_event_callback)(int event, gpointer event_data, gsize size); typedef struct { @@ -54,6 +56,11 @@ typedef struct { char name[BT_DEVICE_NAME_LENGTH_MAX + 1]; } bt_name_t; +typedef struct { + int data_len; /**< manafacturer specific data length */ + char data[BT_DEVICE_MANUFACTURER_DATA_LEN_MAX]; +} oal_manufacturer_data_t; + typedef enum { OAL_STATUS_SUCCESS, /* Generic */ diff --git a/bt-oal/oal-adapter-mgr.c b/bt-oal/oal-adapter-mgr.c index 3355180..56af6d1 100644 --- a/bt-oal/oal-adapter-mgr.c +++ b/bt-oal/oal-adapter-mgr.c @@ -738,6 +738,22 @@ oal_status_t adapter_set_le_static_random_address(int enable) return ret; } +oal_status_t adapter_set_manufacturer_data(oal_manufacturer_data_t *m_data) +{ + int ret; + + CHECK_OAL_INITIALIZED(); + API_TRACE(); + + OAL_CHECK_PARAMETER(m_data, return); + ret = blued_api->adapter_le_set_manufacturer_data((bt_manufacturer_data_t*)m_data); + if (ret != BT_STATUS_SUCCESS) + BT_ERR("Setting manufacturer data Failed: [%s]",status2string(ret)); + + ret = convert_to_oal_status(ret); + return ret; +} + oal_status_t adapter_set_white_list(bt_address_t *device_address, int address_type, bool is_add) { int ret; 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 5408846..f2e41bd 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 @@ -1791,6 +1791,33 @@ int _bt_set_white_list(bluetooth_device_address_t *device_address, int address_t return result; } +int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data) +{ + GVariant *manufac_data, *param = NULL; + int result = BLUETOOTH_ERROR_NONE; + + BT_CHECK_PARAMETER(m_data, return); + + if (_bt_adapter_get_status() != BT_ACTIVATED && + _bt_adapter_get_le_status() != BT_LE_ACTIVATED) + return BLUETOOTH_ERROR_DEVICE_NOT_ENABLED; + + result = adapter_set_manufacturer_data((oal_manufacturer_data_t*)m_data); + if (result != OAL_STATUS_SUCCESS) { + BT_ERR("Set manufacturer data Failed %d", result); + return BLUETOOTH_ERROR_INTERNAL; + } + /*data has been successfully sent to the stack, inititate manufacturer data change event */ + manufac_data = g_variant_new_from_data((const GVariantType *)"ay", + m_data->data, m_data->data_len, TRUE, NULL, NULL); + param = g_variant_new("(@ay)", manufac_data); + _bt_send_event(BT_ADAPTER_EVENT, + BLUETOOTH_EVENT_MANUFACTURER_DATA_CHANGED, + param); + + return result; +} + /*************************************** LE Scan APIs *********************************************/ int _bt_set_le_static_random_address(gboolean is_enable) diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index 9ff9746..d0c369c 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -900,6 +900,14 @@ int __bt_bluez_request(int function_name, result = _bt_set_white_list(&address, address_type, is_add); break; } + case BT_SET_MANUFACTURER_DATA: { + bluetooth_manufacturer_data_t m_data = { 0 }; + __bt_service_get_parameters(in_param1, + &m_data, sizeof(bluetooth_manufacturer_data_t)); + result = _bt_set_manufacturer_data(&m_data); + break; + } + case BT_IS_DEVICE_CONNECTED: { bluetooth_device_address_t address = { {0} }; gboolean connected = FALSE; diff --git a/bt-service-adaptation/services/include/bt-service-core-adapter-le.h b/bt-service-adaptation/services/include/bt-service-core-adapter-le.h index 8e76e76..a505a19 100644 --- a/bt-service-adaptation/services/include/bt-service-core-adapter-le.h +++ b/bt-service-adaptation/services/include/bt-service-core-adapter-le.h @@ -98,6 +98,8 @@ int _bt_set_le_static_random_address(gboolean is_enable); int _bt_set_le_privacy(gboolean set_privacy); int _bt_set_white_list(bluetooth_device_address_t *device_address, int address_type, bool is_add); + +int _bt_set_manufacturer_data(bluetooth_manufacturer_data_t *m_data); #ifdef __cplusplus } #endif /* __cplusplus */