From 2577dd15729dbed8e2dd652251536a777b06cc95 Mon Sep 17 00:00:00 2001 From: Gowtham Anandha Babu Date: Fri, 23 Jun 2017 14:55:10 +0530 Subject: [PATCH] [OTP] Handle Object Delete request Change-Id: Ie4dcc536892d78ed9672fa40748363d9a2454879 Signed-off-by: Gowtham Anandha Babu --- bt-otp/bt-otpserver.c | 60 +++++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/bt-otp/bt-otpserver.c b/bt-otp/bt-otpserver.c index 5361c71..4948a8c 100644 --- a/bt-otp/bt-otpserver.c +++ b/bt-otp/bt-otpserver.c @@ -298,7 +298,7 @@ int _bt_otp_prepare_ots(void) char *desc_uuid; bt_gatt_characteristic_property_t props; bt_gatt_permission_t perms; - char supp_feat[OTP_FEATURE_LENGTH] = { 0x9C, 0x00, 0x00, 0x00, + char supp_feat[OTP_FEATURE_LENGTH] = { 0xDC, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00 }; ret = bluetooth_gatt_init(); @@ -510,11 +510,6 @@ void _bt_otp_start_write_on_fd() char file_path[BT_FILE_PATH_MAX_LEN] = {0, }; int length; - if (!selected_object) { - BT_DBG("Object not selected"); - return; - } - snprintf(file_path, sizeof(file_path), "%s%s", directory, selected_object->name); BT_DBG("file_path = [%s]", file_path); @@ -739,7 +734,8 @@ static void _bt_otp_method(GDBusConnection *connection, object->curr_size = (uint32_t) st.st_size; object->alloc_size = (uint32_t) st.st_size; object->id = object_id; - object->props = OBJECT_READ | OBJECT_WRITE | OBJECT_EXECUTE; + object->props = OBJECT_READ | OBJECT_WRITE | + OBJECT_EXECUTE | OBJECT_DELETE; otp_object_list = g_slist_append(otp_object_list, object); @@ -1114,16 +1110,17 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset, char *remote_addr, struct indicate_info *info) { int ret = OACP_SUCCESS; - int app_err = BLUETOOTH_ERROR_NONE; + int err = BLUETOOTH_ERROR_NONE; int opcode = value[0]; uint32_t object_offset, length, object_size; uint8_t mode = 0; char *uuid; - char absolute_path[BT_FILE_PATH_MAX_LEN] = {0, }; + char absolute_file_path[BT_FILE_PATH_MAX_LEN] = {0, }; BT_INFO("OACP Opcode 0x%d", opcode); - if (!otp_object_list) { + if (!selected_object) { + BT_DBG("Object not selected"); ret = OACP_INVALID_OBJ; goto fail; } @@ -1152,31 +1149,39 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset, timeout_id = g_timeout_add(BT_OACP_MAX_TIMEOUT, (GSourceFunc)__bt_oacp_create_timeout_cb, NULL); g_free(uuid); - ret = OACP_SUCCESS; break; case OACP_DELETE: - ret = OACP_OPCODE_NOT_SUPPORTED; + snprintf(absolute_file_path, sizeof(absolute_file_path), + "%s%s", directory, selected_object->name); + + BT_DBG("absolute_file_path = [%s]", absolute_file_path); + + if (remove(absolute_file_path) != 0) { + BT_DBG("Error: unable to delete the file"); + ret = OACP_OPERATION_FAILED; + goto fail; + } + + BT_DBG("File deleted successfully"); + selected_object = NULL; break; case OACP_CALC_CHECKSUM: ret = OACP_OPCODE_NOT_SUPPORTED; break; case OACP_EXECUTE: - if (!selected_object) { - BT_DBG("Object not selected"); + snprintf(absolute_file_path, sizeof(absolute_file_path), + "file://%s%s", directory, selected_object->name); + + BT_DBG("absolute_file_path = [%s]", absolute_file_path); + + err = _bt_otp_send_launch_request(absolute_file_path); + if (err != BLUETOOTH_ERROR_NONE) { + BT_DBG("Error: unable to launch the file"); ret = OACP_OPERATION_FAILED; goto fail; } - snprintf(absolute_path, sizeof(absolute_path), "file://%s%s", directory, - selected_object->name); - - BT_DBG("absolute_path = [%s]", absolute_path); - - app_err = _bt_otp_send_launch_request(absolute_path); - if (app_err == BLUETOOTH_ERROR_NONE) - ret = OACP_SUCCESS; - else - ret = OACP_OPERATION_FAILED; + BT_DBG("Successfully launched the file"); break; case OACP_READ: case OACP_WRITE: @@ -1212,13 +1217,12 @@ int _bt_otp_oacp_write_cb(char *value, int len, int offset, oacp_op->length_sofar = 0; oacp_op->fp = NULL; - app_err = _bt_otp_open_otc_and_listen(remote_addr, "ListenOtc"); - if (app_err != BLUETOOTH_ERROR_NONE) { + err = _bt_otp_open_otc_and_listen(remote_addr, "ListenOtc"); + if (err != BLUETOOTH_ERROR_NONE) { ret = OACP_OPERATION_FAILED; _bt_otp_free_oacp_op(); goto fail; } - ret = OACP_SUCCESS; break; case OACP_ABORT: ret = OACP_OPCODE_NOT_SUPPORTED; @@ -1232,7 +1236,7 @@ fail: info->req_opcode = opcode; info->result_code = ret; info->resp_param = NULL; - return app_err; + return BLUETOOTH_ERROR_NONE; } void convert_to_hex(struct object_metadata *object, char *type, char *value) -- 2.7.4