diff options
author | Gowtham Anandha Babu <gowtham.ab@samsung.com> | 2017-06-23 14:56:15 +0530 |
---|---|---|
committer | Gowtham Anandha Babu <gowtham.ab@samsung.com> | 2017-06-23 14:56:15 +0530 |
commit | 01ac60186b2d2425dfc2748c9fa7681e65dfba1f (patch) | |
tree | 27bb03ef0f48ba409c235e5358bbe4045e7f41ba /src/bluetooth-otp.c | |
parent | 45401edbbc2301d947f87a0dcac302b42aca3f3a (diff) | |
download | bluetooth-01ac60186b2d2425dfc2748c9fa7681e65dfba1f.tar.gz bluetooth-01ac60186b2d2425dfc2748c9fa7681e65dfba1f.tar.bz2 bluetooth-01ac60186b2d2425dfc2748c9fa7681e65dfba1f.zip |
[OTP] Expose Object Delete API
Change-Id: I9bdc093e89b15299258233ba47df9bc5baf547df
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
Diffstat (limited to 'src/bluetooth-otp.c')
-rw-r--r-- | src/bluetooth-otp.c | 103 |
1 files changed, 103 insertions, 0 deletions
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; +} |