From 01ac60186b2d2425dfc2748c9fa7681e65dfba1f Mon Sep 17 00:00:00 2001 From: Gowtham Anandha Babu Date: Fri, 23 Jun 2017 14:56:15 +0530 Subject: [PATCH] [OTP] Expose Object Delete API Change-Id: I9bdc093e89b15299258233ba47df9bc5baf547df Signed-off-by: Gowtham Anandha Babu --- include/bluetooth_internal.h | 7 ++ include/bluetooth_type_internal.h | 8 +++ src/bluetooth-otp.c | 103 ++++++++++++++++++++++++++++++ test/bt_unit_test.c | 23 +++++++ test/bt_unit_test.h | 1 + 5 files changed, 142 insertions(+) diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 24b080a..0c8e16d 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -4132,6 +4132,13 @@ int bt_otp_client_write_object(bt_otp_client_h otp_client, int bt_otp_client_execute_object(bt_otp_client_h otp_client, bt_otp_client_object_execute_cb callback, void *user_data); +/** + * @internal + * @brief OTP client API to delete object on remote server + */ +int bt_otp_client_delete_object(bt_otp_client_h otp_client, + bt_otp_client_object_delete_cb callback, + void *user_data); /** * @} */ diff --git a/include/bluetooth_type_internal.h b/include/bluetooth_type_internal.h index e21a04a..0748099 100644 --- a/include/bluetooth_type_internal.h +++ b/include/bluetooth_type_internal.h @@ -1003,6 +1003,14 @@ typedef void (*bt_otp_client_object_write_cb) typedef void (*bt_otp_client_object_execute_cb) (int result, const char *remote_address, unsigned long long obj_id, void *user_data); +/** + * @internal + * @since_tizen 4.0 + * @brief OTP Client profile object delete callback + */ +typedef void (*bt_otp_client_object_delete_cb) + (int result, const char *remote_address, unsigned long long obj_id, void *user_data); + /** * @} */ diff --git a/src/bluetooth-otp.c b/src/bluetooth-otp.c index cf1039b..b098a70 100644 --- a/src/bluetooth-otp.c +++ b/src/bluetooth-otp.c @@ -61,6 +61,8 @@ #define BT_OTP_OBJECT_LAST_MODIFIED_UUID "00002ac2-0000-1000-8000-00805f9b34fb" #define BT_OTP_OBJECT_ID_UUID "00002ac3-0000-1000-8000-00805f9b34fb" #define BT_OTP_OBJECT_PROP_UUID "00002ac4-0000-1000-8000-00805f9b34fb" +#define BT_OTP_OBJECT_LIST_FILTER_UUID "00002ac7-0000-1000-8000-00805f9b34fb" +#define BT_OTP_OBJECT_CHANGED_UUID "00002ac8-0000-1000-8000-00805f9b34fb" /* OLCP opcodes */ #define OLCP_FIRST 0x01 @@ -130,10 +132,12 @@ #define BT_OTP_IS_OACP_CREATE_SUPPORTED(feature) feature & 0x8000000000000000 #define BT_OTP_IS_OACP_WRITE_SUPPORTED(feature) feature & 0x0400000000000000 #define BT_OTP_IS_OACP_EXECUTE_SUPPORTED(feature) feature & 0x1000000000000000 +#define BT_OTP_IS_OACP_DELETE_SUPPORTED(feature) feature & 0x4000000000000000 #define BT_OTP_IS_READ_PERMITTED(props) props & OBJECT_READ #define BT_OTP_IS_WRITE_PERMITTED(props) props & OBJECT_WRITE #define BT_OTP_IS_EXECUTE_PERMITTED(props) props & OBJECT_EXECUTE +#define BT_OTP_IS_DELETE_PERMITTED(props) props & OBJECT_DELETE /* OTP Object Type Custom UUIDs */ /* In SIG Assigned numbers not available */ @@ -150,6 +154,7 @@ typedef enum { BT_OTP_OBJECT_CREATE, BT_OTP_OBJECT_WRITE, BT_OTP_OBJECT_EXECUTE, + BT_OTP_OBJECT_DELETE, } bt_otp_api_info_e; typedef struct { @@ -187,6 +192,8 @@ typedef struct { char *otp_id_obj_path; /* OTP Object ID characteristic handle */ char *otp_props_obj_path; /* OTP Object Properties characteristic handle */ + char *otp_list_filter_obj_path; /* OTP Object List Filter handle */ + bool oacp_cccd_enabled; /* OTP OACP Control Point CCCD is enabled or not */ bool olcp_cccd_enabled; /* OTP OLCP Control Point CCCD is enabled or not */ bool multiple_obj_supp; /* Indicates whether remote server supports @@ -250,6 +257,8 @@ static void _bt_otp_client_send_write_object_callback(int result, unsigned int length, bt_otp_client_s *otp_client_s); static void _bt_otp_client_send_execute_object_callback(int result, bt_otp_client_s *otp_client_s); +static void _bt_otp_client_send_delete_object_callback(int result, + bt_otp_client_s *otp_client_s); int __bt_check_otp_server_init_status(void) { @@ -372,6 +381,8 @@ static void __bt_otp_client_reset_server_data(bt_otp_client_s *otp_client_s) free_object_path(otp_client_s->otp_id_obj_path); otp_client_s->otp_props_obj_path = free_object_path(otp_client_s->otp_props_obj_path); + otp_client_s->otp_list_filter_obj_path = + free_object_path(otp_client_s->otp_list_filter_obj_path); /* Reset CCCD */ otp_client_s->oacp_cccd_enabled = FALSE; @@ -593,6 +604,14 @@ static int __bt_update_otp_server_data(bluetooth_device_address_t *address, bt_o otp_client_s->otp_props_obj_path = g_strdup(characteristic.handle); BT_DBG("OTP Object Properties handle [%s]", otp_client_s->otp_props_obj_path); + } else if (g_strstr_len(characteristic.uuid, -1, BT_OTP_OBJECT_LIST_FILTER_UUID)) { + BT_DBG("OTP Object List Filter characteristic discovered"); + + if (otp_client_s->otp_list_filter_obj_path) + g_free(otp_client_s->otp_list_filter_obj_path); + otp_client_s->otp_list_filter_obj_path = g_strdup(characteristic.handle); + + BT_DBG("OTP Object List Filter handle [%s]", otp_client_s->otp_list_filter_obj_path); } else { BT_DBG("Other OTP Characteristic handle [%s]", characteristic.handle); BT_DBG("UUID [%s]", characteristic.uuid); @@ -1233,6 +1252,10 @@ fail: _bt_otp_client_send_execute_object_callback(result, otp_client_s); __bt_otp_reset_api_info(otp_client_s); break; + case BT_OTP_OBJECT_DELETE: + _bt_otp_client_send_delete_object_callback(result, otp_client_s); + __bt_otp_reset_api_info(otp_client_s); + break; case BT_OTP_NO_OPERATION: break; } @@ -1326,6 +1349,9 @@ void _bt_otp_client_indication(int result, bluetooth_otp_resp_info_t *info) } break; case OACP_DELETE: + BT_INFO("OACP_DELETE Indication received"); + goto oacp_done; + break; case OACP_CALC_CHECKSUM: break; case OACP_EXECUTE: @@ -1372,6 +1398,9 @@ oacp_done: } else if (otp_client_s->curr_op == BT_OTP_OBJECT_EXECUTE) { _bt_otp_client_send_execute_object_callback(result, otp_client_s); __bt_otp_reset_api_info(otp_client_s); + } else if (otp_client_s->curr_op == BT_OTP_OBJECT_DELETE) { + _bt_otp_client_send_delete_object_callback(result, otp_client_s); + __bt_otp_reset_api_info(otp_client_s); } } else if (!g_strcmp0(otp_client_s->otp_olcp_control_point, info->handle)) { uint8_t resp_code = info->data[0]; @@ -2255,3 +2284,77 @@ int bt_otp_client_execute_object(bt_otp_client_h otp_client, return error_code; } + +static void _bt_otp_client_send_delete_object_callback(int result, + bt_otp_client_s *otp_client_s) +{ + ((bt_otp_client_object_delete_cb)otp_client_s->callback)( + result, otp_client_s->remote_address, + otp_client_s->object_id, otp_client_s->user_data); + + if (result == BLUETOOTH_ERROR_NONE) + otp_client_s->object_id = 0; +} + +int bt_otp_client_delete_object(bt_otp_client_h otp_client, + bt_otp_client_object_delete_cb callback, + void *user_data) +{ + int error_code; + bt_otp_client_s *otp_client_s = (bt_otp_client_s *)otp_client; + object_metadata *object_info = NULL; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(otp_client_s); + + if (_bt_otp_client_find(otp_client_s->remote_address) == NULL) + return BT_ERROR_NOT_INITIALIZED; + + if (otp_client_s->connected == false) { + BT_ERR("Remote device [%s] is not conencted", otp_client_s->remote_address); + return BT_ERROR_OPERATION_FAILED; + } + + if (otp_client_s->curr_op != BT_OTP_NO_OPERATION) { + BT_DBG("OTP Client is busy"); + return BT_ERROR_OPERATION_FAILED; + } + + if (~BT_OTP_IS_OACP_DELETE_SUPPORTED(otp_client_s->otp_feature)) { + BT_INFO("OACP Delete not supported"); + return BT_ERROR_OPERATION_FAILED; + } + + object_info = _bt_otp_client_find_object(otp_client_s->object_list, + otp_client_s->object_id); + if (!object_info) { + BT_INFO("Object Not Found [%llu]", otp_client_s->object_id); + return BT_ERROR_OPERATION_FAILED; + } + + if (~BT_OTP_IS_DELETE_PERMITTED(object_info->props)) { + BT_INFO("Delete not permitted"); + return BT_ERROR_OPERATION_FAILED; + } + + BT_DBG("OTP client delete object [%llu] in Remote device [%s]", + otp_client_s->object_id, otp_client_s->remote_address); + + otp_client_s->callback = callback; + otp_client_s->user_data = user_data; + otp_client_s->curr_op = BT_OTP_OBJECT_DELETE; + + uint8_t value[1]; + value[0] = OACP_DELETE; + + error_code = bluetooth_otp_write_characteristics_value(otp_client_s->otp_oacp_control_point, + value, 1); + if (error_code != BT_ERROR_NONE) { + BT_ERR("Failed to write control point : %s(0x%08x)", + _bt_convert_error_to_string(error_code), error_code); + __bt_otp_reset_api_info(otp_client_s); + } + + return error_code; +} diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 5f8fd2b..1037274 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -1188,6 +1188,8 @@ tc_table_t tc_otp[] = { , BT_UNIT_TEST_FUNCTION_OTP_CLIENT_WRITE_OBJ}, {"bt_otp_client_execute_object" , BT_UNIT_TEST_FUNCTION_OTP_CLIENT_EXECUTE_OBJ}, + {"bt_otp_client_delete_object" + , BT_UNIT_TEST_FUNCTION_OTP_CLIENT_DELETE_OBJ}, {NULL , 0x0000}, }; @@ -3319,6 +3321,19 @@ static void __bt_otp_client_object_execute_cb(int result, const char *remote_add BT_ERR("Object[%llu] launch failed!", obj_id); } +static void __bt_otp_client_object_delete_cb(int result, const char *remote_address, + unsigned long long obj_id, void *user_data) +{ + TC_PRT("__bt_otp_client_object_delete_cb"); + TC_PRT("Result: %s", __bt_get_error_message(result)); + TC_PRT("Remote addr [%s]", remote_address); + + if (result == BT_ERROR_NONE) + TC_PRT("Object[%llu] deleted successfully!", obj_id); + else + BT_ERR("Object[%llu] delete failed!", obj_id); +} + static void __bt_initialize_all(void) { int ret; @@ -10541,6 +10556,14 @@ int test_input_callback(void *data) } break; } + case BT_UNIT_TEST_FUNCTION_OTP_CLIENT_DELETE_OBJ: { + if (otp_client) { + ret = bt_otp_client_delete_object(otp_client, + __bt_otp_client_object_delete_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } + break; + } case BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: need_to_set_params = true; TC_PRT("Select the function again"); diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h index f0529f7..b5f47b9 100644 --- a/test/bt_unit_test.h +++ b/test/bt_unit_test.h @@ -499,6 +499,7 @@ typedef enum { BT_UNIT_TEST_FUNCTION_OTP_CLIENT_CREATE_OBJ, BT_UNIT_TEST_FUNCTION_OTP_CLIENT_WRITE_OBJ, BT_UNIT_TEST_FUNCTION_OTP_CLIENT_EXECUTE_OBJ, + BT_UNIT_TEST_FUNCTION_OTP_CLIENT_DELETE_OBJ, BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS = 0XFF, } bt_unit_test_function_e; -- 2.34.1