[OTP] Fix to track ongoing APIs 80/132680/2
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 7 Jun 2017 06:32:56 +0000 (12:02 +0530)
committerGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 7 Jun 2017 06:44:53 +0000 (12:14 +0530)
Change-Id: Ic5e59a0f12f5f6b0c0ab45eb0ea96bcac7dd9307
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
src/bluetooth-otp.c

index 3ed8125c5adc461b2e0ed03b4944688d9a9fe88b..05fbb3def4be521a032d0a900b0b56c9c71de650 100644 (file)
 
 #define BT_OTP_IS_READ_PERMITTED(props)        props & OBJECT_READ
 
+typedef enum {
+       BT_OTP_NO_OPERATION = 0,
+       BT_OTP_OBJECT_DISCOVERY,
+       BT_OTP_OBJECT_READ,
+} bt_otp_api_info_e;
+
 typedef struct {
        char *name;
        char *type;
@@ -147,12 +153,6 @@ typedef struct {
        const void *connection_callback;
        void *conn_cb_user_data;
 
-       const void *object_discovery_complete_cb;
-       void *discovery_user_data;
-
-       const void *object_read_complete_cb;
-       void *read_object_user_data;
-
        char *otp_service_handle;               /* OTP Service Handle */
        char *otp_feature_obj_path;             /* OTP feature characteristic handle */
        uint64_t otp_feature;                   /* OTP feature value */
@@ -172,13 +172,16 @@ typedef struct {
 
        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 object_discovery;                  /* Indicates current state of the object_discovery */
        bool multiple_obj_supp;                 /* Indicates whether remote server supports
                                                 * multiple-objects or not
                                                 */
-       bool oacp_read_status;                  /* Indicate whether oacp read is completed or not */
        GSList *object_list;                    /* List of server objects */
        uint64_t object_id;                     /* ID of current object */
+
+       /* Ongoing API Information */
+       bt_otp_api_info_e curr_op;
+       const void *callback;
+       void *user_data;
 } bt_otp_client_s;
 
 typedef struct {
@@ -201,6 +204,7 @@ guint id;
 object_metadata *_bt_otp_client_find_object(GSList *list, uint64_t id);
 static void _bt_otp_client_notify_read_object_status(int result,
                        char *file_path, bt_otp_client_s *otp_client_s);
+void __bt_otp_reset_api_info(bt_otp_client_s *otp_client_s);
 
 int __bt_check_otp_server_init_status(void)
 {
@@ -652,9 +656,8 @@ int bt_otp_client_create(const char *remote_address, bt_otp_client_h *otp_client
        otp_client_s->otp_olcp_control_point = NULL;
        otp_client_s->olcp_cccd_enabled = FALSE;
        otp_client_s->oacp_cccd_enabled = FALSE;
-       otp_client_s->object_discovery = FALSE;
+       otp_client_s->curr_op = BT_OTP_NO_OPERATION;
        otp_client_s->multiple_obj_supp = FALSE;
-       otp_client_s->oacp_read_status = FALSE;
 
        otp_client_list = g_slist_append(otp_client_list, otp_client_s);
        *otp_client = (bt_otp_client_h)otp_client_s;
@@ -753,8 +756,8 @@ void _bt_otp_send_discovery_callback(int result, bt_otp_client_s *otp_client_s)
        GSList *l;
        int k;
        if (result != BLUETOOTH_ERROR_NONE) {
-               ((bt_otp_client_object_discovery_cb)otp_client_s->object_discovery_complete_cb)(
-               result, otp_client_s->remote_address, NULL, otp_client_s->discovery_user_data);
+               ((bt_otp_client_object_discovery_cb)otp_client_s->callback)(
+               result, otp_client_s->remote_address, NULL, otp_client_s->user_data);
                return;
        }
 
@@ -780,8 +783,8 @@ void _bt_otp_send_discovery_callback(int result, bt_otp_client_s *otp_client_s)
                obj_list->data[k] = m_data;
                k++;
        }
-       ((bt_otp_client_object_discovery_cb)otp_client_s->object_discovery_complete_cb)(
-               BLUETOOTH_ERROR_NONE, otp_client_s->remote_address, obj_list, otp_client_s->discovery_user_data);
+       ((bt_otp_client_object_discovery_cb)otp_client_s->callback)(
+               BLUETOOTH_ERROR_NONE, otp_client_s->remote_address, obj_list, otp_client_s->user_data);
 }
 
 void _bt_otp_client_read_value_response(int result, char *char_path,
@@ -795,8 +798,10 @@ void _bt_otp_client_read_value_response(int result, char *char_path,
 
        BT_DBG("OTP client Read Value Response [%d] [%s] [%s] [%d]", result,
                                                        char_path, value, len);
-       if (result != BLUETOOTH_ERROR_NONE)
+       if (result != BLUETOOTH_ERROR_NONE) {
                BT_INFO("Read failed for [%s]", char_path);
+               goto read_fail;
+       }
 
        otp_client_s = _bt_otp_client_find(remote_address);
        if (otp_client_s == NULL)
@@ -832,111 +837,109 @@ void _bt_otp_client_read_value_response(int result, char *char_path,
                        }
        } else {
                if (!g_strcmp0(otp_client_s->otp_name_obj_path, char_path)) {
+                       char *name = NULL;
+                       name = g_strndup(value, len);
+                       BT_INFO("Object Name [%s]", name);
 
-                       if (result != BLUETOOTH_ERROR_NONE) {
-                               BT_INFO("Read Charc Value Response Failed %s(0x%08x)",
-                                                       _bt_convert_error_to_string(error_code), error_code);
-                               return;
-                       }
-
-                       metadata->name = g_strndup(value, len);
-                       BT_INFO("Object Name [%s]", metadata->name);
-
-                       if (otp_client_s->object_discovery) {
+                       if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                               metadata->name = g_strdup(name);
                                error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_type_obj_path);
-                               if (error_code != BLUETOOTH_ERROR_NONE)
+                               if (error_code != BLUETOOTH_ERROR_NONE) {
                                        BT_INFO("Read Charc Value Failed %s(0x%08x)",
                                                        _bt_convert_error_to_string(error_code), error_code);
+                                       goto read_fail;
+                               }
                        }
+                       g_free(name);
                } else if (!g_strcmp0(otp_client_s->otp_type_obj_path, char_path)) {
+                       char *type = NULL;
+                       type = g_strndup(value, len);
+                       BT_INFO("Object Type [%s]", type);
 
-                       if (result != BLUETOOTH_ERROR_NONE) {
-                               return;
-                       }
-                       metadata->type = g_strndup(value, len);
-                       BT_INFO("Object Type [%s]", metadata->type);
-
-                       if (otp_client_s->object_discovery) {
+                       if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                               metadata->type = g_strdup(type);
                                error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_size_obj_path);
-                               if (error_code != BLUETOOTH_ERROR_NONE)
+                               if (error_code != BLUETOOTH_ERROR_NONE) {
                                        BT_INFO("Read Charc Value Failed %s(0x%08x)",
                                                        _bt_convert_error_to_string(error_code), error_code);
+                                       goto read_fail;
+                               }
                        }
 
+                       g_free(type);
                } else if (!g_strcmp0(otp_client_s->otp_size_obj_path, char_path)) {
+                       uint32_t csize, asize;
+                       csize = (uint32_t)(value[3] & 0xFF) << 24       |
+                                                       (uint32_t)(value[2] & 0xFF) << 16       |
+                                                       (uint32_t)(value[1] & 0xFF) << 8        |
+                                                       (uint32_t)(value[0] & 0xFF);
 
-                       uint32_t curr_size, alloc_size;
-
-                       if (result != BLUETOOTH_ERROR_NONE) {
-                               return;
-                       }
-
-                       curr_size = (uint32_t)(value[3] & 0xFF) << 24   |
-                                               (uint32_t)(value[2] & 0xFF) << 16       |
-                                               (uint32_t)(value[1] & 0xFF) << 8        |
-                                               (uint32_t)(value[0] & 0xFF);
-
-                       alloc_size =    (uint32_t)(value[7] & 0xFF) << 24       |
+                       asize = (uint32_t)(value[7] & 0xFF) << 24       |
                                                        (uint32_t)(value[6] & 0xFF) << 16       |
                                                        (uint32_t)(value[5] & 0xFF) << 8        |
                                                        (uint32_t)(value[4] & 0xFF);
 
-                       metadata->curr_size = curr_size;
-                       metadata->alloc_size = alloc_size;
-                       BT_INFO("Object Size curr[%lu] alloc[%lu]", metadata->curr_size, metadata->alloc_size);
+                       BT_INFO("Object Size curr[%lu] alloc[%lu]", csize, asize);
 
-                       if (otp_client_s->object_discovery) {
+                       if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                               metadata->curr_size = csize;
+                               metadata->alloc_size = asize;
                                error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_props_obj_path);
-                               if (error_code != BLUETOOTH_ERROR_NONE)
+                               if (error_code != BLUETOOTH_ERROR_NONE) {
                                        BT_INFO("Read Charc Value Failed %s(0x%08x)",
                                                        _bt_convert_error_to_string(error_code), error_code);
+                                       goto read_fail;
+                               }
                        }
 
                } else if (!g_strcmp0(otp_client_s->otp_props_obj_path, char_path)) {
-
-                       if (result != BLUETOOTH_ERROR_NONE) {
-                               return;
-                       }
-                       metadata->props = (uint32_t)(value[3] & 0xFF) << 24             |
+                       uint32_t props;
+                       props = (uint32_t)(value[3] & 0xFF) << 24               |
                                                (uint32_t)(value[2] & 0xFF) << 16       |
                                                (uint32_t)(value[1] & 0xFF) << 8        |
                                                (uint32_t)(value[0] & 0xFF);
-                       BT_INFO("Object Properties [%lu]", metadata->props);
+                       BT_INFO("Object Properties [%lu]", props);
 
                        /* First-created & Last-modified are optional charcacteristics */
-                       if (otp_client_s->otp_first_created_obj_path && otp_client_s->object_discovery) {
-                               error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_first_created_obj_path);
-                               if (error_code != BLUETOOTH_ERROR_NONE)
-                                       BT_INFO("Read Charc Value Failed %s(0x%08x)",
-                                                               _bt_convert_error_to_string(error_code), error_code);
-                       } else if (otp_client_s->otp_last_modified_obj_path && otp_client_s->object_discovery) {
-                               error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_last_modified_obj_path);
-                               if (error_code != BLUETOOTH_ERROR_NONE)
-                                       BT_INFO("Read Charc Value Failed %s(0x%08x)",
+                       if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                               metadata->props = props;
+                               if (otp_client_s->otp_first_created_obj_path) {
+                                       error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_first_created_obj_path);
+                                       if (error_code != BLUETOOTH_ERROR_NONE) {
+                                               BT_INFO("Read Charc Value Failed %s(0x%08x)",
                                                                _bt_convert_error_to_string(error_code), error_code);
-                       } else {
-                               /* Reading Object ID characteristics makes sense if server
-                                * supports multiple objects.
-                                */
-                               if (otp_client_s->multiple_obj_supp) {
-                                       metadata->id = 0x256;
-                                       otp_client_s->object_id = metadata->id;
-                                       otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
-                                       _bt_otp_send_discovery_callback(BLUETOOTH_ERROR_NONE, otp_client_s);
-                               } else {
-                                       if (otp_client_s->otp_id_obj_path && otp_client_s->object_discovery) {
-                                               error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_id_obj_path);
-                                               if (error_code != BLUETOOTH_ERROR_NONE)
-                                                       BT_INFO("Read Charc Value Failed %s(0x%08x)",
+                                               goto read_fail;
+                                       }
+                               } else if (otp_client_s->otp_last_modified_obj_path) {
+                                       error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_last_modified_obj_path);
+                                       if (error_code != BLUETOOTH_ERROR_NONE) {
+                                               BT_INFO("Read Charc Value Failed %s(0x%08x)",
                                                                        _bt_convert_error_to_string(error_code), error_code);
+                                               goto read_fail;
+                                       }
+                               } else {
+                                       /* Reading Object ID characteristics makes sense if server
+                                        * supports multiple objects.
+                                        */
+                                       if (otp_client_s->multiple_obj_supp) {
+                                               metadata->id = 0x256;
+                                               otp_client_s->object_id = metadata->id;
+                                               otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
+                                               _bt_otp_send_discovery_callback(BLUETOOTH_ERROR_NONE, otp_client_s);
+                                               __bt_otp_reset_api_info(otp_client_s);
+                                       } else {
+                                               if (otp_client_s->otp_id_obj_path) {
+                                                       error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_id_obj_path);
+                                                       if (error_code != BLUETOOTH_ERROR_NONE) {
+                                                               BT_INFO("Read Charc Value Failed %s(0x%08x)",
+                                                                               _bt_convert_error_to_string(error_code), error_code);
+                                                               goto read_fail;
+                                                       }
+                                               }
                                        }
                                }
                        }
                } else if (!g_strcmp0(otp_client_s->otp_first_created_obj_path, char_path)) {
-
-                       if (result != BLUETOOTH_ERROR_NONE) {
-                               return;
-                       }
                        struct tm tm = {0};
                        uint16_t year = (uint16_t)(value[1] & 0xFF) << 8        |
                                                        (uint16_t)(value[0] & 0xFF);
@@ -949,33 +952,36 @@ void _bt_otp_client_read_value_response(int result, char *char_path,
                        tm.tm_sec = value[6] & 0xFF;
                        BT_INFO("Object First Created [%d]-[%d]-[%d]\t[%d][%d][%d]", tm.tm_mday,
                                                tm.tm_mon, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec);
-                       metadata->first_created = mktime(&tm);
 
-                       if (otp_client_s->otp_last_modified_obj_path && otp_client_s->object_discovery) {
-                               error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_last_modified_obj_path);
-                               if (error_code != BLUETOOTH_ERROR_NONE)
-                                       BT_INFO("Read Charc Value Failed %s(0x%08x)",
-                                                               _bt_convert_error_to_string(error_code), error_code);
-                       } else {
-                               if (otp_client_s->multiple_obj_supp) {
-                                       metadata->id = 0x256;
-                                       otp_client_s->object_id = metadata->id;
-                                       otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
-                                       _bt_otp_send_discovery_callback(BLUETOOTH_ERROR_NONE, otp_client_s);
+                       if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                               metadata->first_created = mktime(&tm);
+                               if (otp_client_s->otp_last_modified_obj_path) {
+                                       error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_last_modified_obj_path);
+                                       if (error_code != BLUETOOTH_ERROR_NONE) {
+                                               BT_INFO("Read Charc Value Failed %s(0x%08x)",
+                                                                       _bt_convert_error_to_string(error_code), error_code);
+                                               goto read_fail;
+                                       }
                                } else {
-                                       if (otp_client_s->otp_id_obj_path && otp_client_s->object_discovery) {
-                                               error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_id_obj_path);
-                                               if (error_code != BLUETOOTH_ERROR_NONE)
-                                                       BT_INFO("Read Charc Value Failed %s(0x%08x)",
-                                                                               _bt_convert_error_to_string(error_code), error_code);
+                                       if (otp_client_s->multiple_obj_supp) {
+                                               metadata->id = 0x256;
+                                               otp_client_s->object_id = metadata->id;
+                                               otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
+                                               _bt_otp_send_discovery_callback(BLUETOOTH_ERROR_NONE, otp_client_s);
+                                               __bt_otp_reset_api_info(otp_client_s);
+                                       } else {
+                                               if (otp_client_s->otp_id_obj_path) {
+                                                       error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_id_obj_path);
+                                                       if (error_code != BLUETOOTH_ERROR_NONE) {
+                                                               BT_INFO("Read Charc Value Failed %s(0x%08x)",
+                                                                                       _bt_convert_error_to_string(error_code), error_code);
+                                                               goto read_fail;
+                                                       }
+                                               }
                                        }
                                }
                        }
                } else if (!g_strcmp0(otp_client_s->otp_last_modified_obj_path, char_path)) {
-
-                       if (result != BLUETOOTH_ERROR_NONE) {
-                               return;
-                       }
                        struct tm tm = {0};
                        uint16_t year = (uint16_t)(value[1] & 0xFF) << 8        |
                                                        (uint16_t)(value[0] & 0xFF);
@@ -988,45 +994,59 @@ void _bt_otp_client_read_value_response(int result, char *char_path,
                        tm.tm_sec = value[6] & 0xFF;
                        BT_INFO("Object Last Modified [%d]-[%d]-[%d]\t[%d][%d][%d]", tm.tm_mday,
                                                tm.tm_mon, tm.tm_year, tm.tm_hour, tm.tm_min, tm.tm_sec);
-                       metadata->last_modified = mktime(&tm);
 
-                       if (otp_client_s->multiple_obj_supp) {
-                               /* None of the optional characteristics supported, so finish object discovery */
-                               metadata->id = 0x256;
-                               otp_client_s->object_id = metadata->id;
-                               otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
-                               _bt_otp_send_discovery_callback(BLUETOOTH_ERROR_NONE, otp_client_s);
-                       } else {
-                               if (otp_client_s->otp_id_obj_path && otp_client_s->object_discovery) {
-                                       error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_id_obj_path);
-                                       if (error_code != BLUETOOTH_ERROR_NONE)
-                                               BT_INFO("Read Charc Value Failed %s(0x%08x)",
-                                                                       _bt_convert_error_to_string(error_code), error_code);
+                       if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                               metadata->last_modified = mktime(&tm);
+                               if (otp_client_s->multiple_obj_supp) {
+                                       /* None of the optional characteristics supported, so finish object discovery */
+                                       metadata->id = 0x256;
+                                       otp_client_s->object_id = metadata->id;
+                                       otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
+                                       _bt_otp_send_discovery_callback(BLUETOOTH_ERROR_NONE, otp_client_s);
+                                       __bt_otp_reset_api_info(otp_client_s);
+                               } else {
+                                       if (otp_client_s->otp_id_obj_path) {
+                                               error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_id_obj_path);
+                                               if (error_code != BLUETOOTH_ERROR_NONE) {
+                                                       BT_INFO("Read Charc Value Failed %s(0x%08x)",
+                                                                               _bt_convert_error_to_string(error_code), error_code);
+                                                       goto read_fail;
+                                               }
+                                       }
                                }
                        }
                } else if (!g_strcmp0(otp_client_s->otp_id_obj_path, char_path)) {
+                       uint64_t id;
+                       id = (uint64_t)(value[5] & 0xFF) << 48  |
+                                       (uint64_t)(value[4] & 0xFF) << 32       |
+                                       (uint64_t)(value[3] & 0xFF) << 24       |
+                                       (uint64_t)(value[2] & 0xFF) << 16       |
+                                       (uint64_t)(value[1] & 0xFF) << 8        |
+                                       (uint64_t)(value[0] & 0xFF);
+                       BT_INFO("Object ID [%llu]", id);
+                       /* TODO: Remove the previous stored object list */
+                       if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                               metadata->id = id;
+                               otp_client_s->object_id = metadata->id;
+                               otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
 
-                       if (result != BLUETOOTH_ERROR_NONE) {
-                               return;
+                               uint8_t value[7] = {0x00};
+                               value[0] = OLCP_NEXT;
+                               error_code = bluetooth_otp_write_characteristics_value(otp_client_s->otp_olcp_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);
+                                       goto read_fail;
+                               }
                        }
-                       metadata->id =  (uint64_t)(value[5] & 0xFF) << 48       |
-                                               (uint64_t)(value[4] & 0xFF) << 32       |
-                                               (uint64_t)(value[3] & 0xFF) << 24       |
-                                               (uint64_t)(value[2] & 0xFF) << 16       |
-                                               (uint64_t)(value[1] & 0xFF) << 8        |
-                                               (uint64_t)(value[0] & 0xFF);
-                       BT_INFO("Object ID [%llu]", metadata->id);
-                       /* Current Selected Object ID */
-                       otp_client_s->object_id = metadata->id;
-                       /* TODO: Remove the previous stored object list */
-                       otp_client_s->object_list = g_slist_append(otp_client_s->object_list, metadata);
-
-                       uint8_t value[7] = {0x00};
-                       value[0] = OLCP_NEXT;
-                       error_code = bluetooth_otp_write_characteristics_value(otp_client_s->otp_olcp_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);
-                               otp_client_s->object_discovery = FALSE;
+               }
+read_fail:
+               if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
+                       if (result != BLUETOOTH_ERROR_NONE) {
+                               _bt_otp_send_discovery_callback(result, otp_client_s);
+                               __bt_otp_reset_api_info(otp_client_s);
+                       } else if (error_code != BLUETOOTH_ERROR_NONE) {
+                               _bt_otp_send_discovery_callback(error_code, otp_client_s);
+                               __bt_otp_reset_api_info(otp_client_s);
                        }
                }
        }
@@ -1043,14 +1063,14 @@ void _bt_otp_client_write_value_response(int result, char *handle)
 
        if (result != BLUETOOTH_ERROR_NONE) {
                BT_DBG("OTP Write Failed");
-               if (otp_client_s->object_discovery) {
+               if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
                        _bt_otp_send_discovery_callback(result, otp_client_s);
-                       otp_client_s->object_discovery = FALSE;
+                       __bt_otp_reset_api_info(otp_client_s);
                }
-               if (otp_client_s->oacp_read_status) {
+               if (otp_client_s->curr_op == BT_OTP_OBJECT_READ) {
                        _bt_otp_client_notify_read_object_status(result,
                                                                NULL, otp_client_s);
-                       otp_client_s->oacp_read_status = FALSE;
+                       __bt_otp_reset_api_info(otp_client_s);
                }
        }
 }
@@ -1152,9 +1172,9 @@ void _bt_otp_client_indication(int result, bluetooth_otp_resp_info_t *info)
                }
                return;
 oacp_fail:
-               if (otp_client_s->oacp_read_status) {
+               if (otp_client_s->curr_op == BT_OTP_OBJECT_READ) {
                        _bt_otp_client_notify_read_object_status(result, NULL, otp_client_s);
-                       otp_client_s->oacp_read_status = FALSE;
+                       __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];
@@ -1226,13 +1246,20 @@ oacp_fail:
                }
                return;
 olcp_fail:
-               if (otp_client_s->object_discovery) {
+               if (otp_client_s->curr_op == BT_OTP_OBJECT_DISCOVERY) {
                        _bt_otp_send_discovery_callback(result, otp_client_s);
-                       otp_client_s->object_discovery = FALSE;
+                       __bt_otp_reset_api_info(otp_client_s);
                }
        }
 }
 
+void __bt_otp_reset_api_info(bt_otp_client_s *otp_client_s)
+{
+       otp_client_s->curr_op = BT_OTP_NO_OPERATION;
+       otp_client_s->callback = NULL;
+       otp_client_s->user_data = NULL;
+}
+
 int bt_otp_client_discover_all_objects(bt_otp_client_h otp_client,
                                                bt_otp_client_object_discovery_cb callback, void *user_data)
 {
@@ -1252,11 +1279,16 @@ int bt_otp_client_discover_all_objects(bt_otp_client_h otp_client,
                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;
+       }
+
        BT_DBG("OTP client Discover objects from Remote device [%s]", otp_client_s->remote_address);
-       otp_client_s->object_discovery_complete_cb = callback;
-       otp_client_s->discovery_user_data = user_data;
+       otp_client_s->curr_op = BT_OTP_OBJECT_DISCOVERY;
+       otp_client_s->callback = callback;
+       otp_client_s->user_data = user_data;
 
-       otp_client_s->object_discovery = TRUE;
        if (!otp_client_s->otp_olcp_control_point) {
                /* Remote server supports only single object */
                otp_client_s->multiple_obj_supp = TRUE;
@@ -1265,7 +1297,8 @@ int bt_otp_client_discover_all_objects(bt_otp_client_h otp_client,
                if (error_code != BLUETOOTH_ERROR_NONE) {
                        BT_INFO("Read Charc Value Failed %s(0x%08x)",
                                                _bt_convert_error_to_string(error_code), error_code);
-                       otp_client_s->object_discovery = FALSE;
+                       error_code = BT_ERROR_OPERATION_FAILED;
+                       __bt_otp_reset_api_info(otp_client_s);
                }
        } else {
                /* Remote server supports multiple objects.
@@ -1276,12 +1309,11 @@ int bt_otp_client_discover_all_objects(bt_otp_client_h otp_client,
                error_code = bluetooth_otp_write_characteristics_value(otp_client_s->otp_olcp_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);
-                       otp_client_s->object_discovery = FALSE;
-                       goto fail;
+                       error_code = BT_ERROR_OPERATION_FAILED;
+                       __bt_otp_reset_api_info(otp_client_s);
                }
        }
 
-fail:
        return error_code;
 }
 
@@ -1353,7 +1385,7 @@ static gboolean __client_data_received_cb(GIOChannel *chan, GIOCondition cond,
        if (!oacp_read_op) {
                char file_path[BT_FILE_PATH_MAX_LEN] = {0, };
                bt_otp_client_s *otp_client_s = NULL;
-               object_metadata *object_info;
+               object_metadata *object_info = NULL;
                uint64_t obj_id;
                FILE *fp = NULL;
 
@@ -1405,9 +1437,9 @@ static void _bt_otp_client_notify_read_object_status(int result,
                                                        char *file_path, bt_otp_client_s *otp_client_s)
 {
 
-       ((bt_otp_client_read_object_complete_cb)otp_client_s->object_read_complete_cb)(
+       ((bt_otp_client_read_object_complete_cb)otp_client_s->callback)(
                                result, otp_client_s->remote_address,
-                               file_path, otp_client_s->read_object_user_data);
+                               file_path, otp_client_s->user_data);
 }
 
 void _bt_otc_connection_state_changed(int result, bluetooth_otc_info_t *otc_info)
@@ -1455,10 +1487,10 @@ void _bt_otc_connection_state_changed(int result, bluetooth_otc_info_t *otc_info
                bt_otp_client_s *otp_client_s = NULL;
                otp_client_s = _bt_otp_client_find(otc_info->address);
 
-               if (otp_client_s->oacp_read_status) {
+               if (otp_client_s && (otp_client_s->curr_op == BT_OTP_OBJECT_READ)) {
                        _bt_otp_client_notify_read_object_status(BLUETOOTH_ERROR_NONE,
                                                                        file_path, otp_client_s);
-                       otp_client_s->oacp_read_status = FALSE;
+                       __bt_otp_reset_api_info(otp_client_s);
                }
        }
 }
@@ -1518,14 +1550,19 @@ int bt_otp_client_read_object_contents(bt_otp_client_h otp_client,
                return BT_ERROR_OPERATION_FAILED;
        }
 
-       otp_client_s->object_read_complete_cb = callback;
-       otp_client_s->read_object_user_data = user_data;
-       otp_client_s->oacp_read_status = TRUE;
+       if (otp_client_s->curr_op != BT_OTP_NO_OPERATION) {
+               BT_DBG("OTP Client is busy");
+               return BT_ERROR_OPERATION_FAILED;
+       }
+
+       otp_client_s->callback = callback;
+       otp_client_s->user_data = user_data;
+       otp_client_s->curr_op = BT_OTP_OBJECT_READ;
 
        uint32_t offset = 0;
        uint32_t length = object_info->curr_size;
 
-       BT_INFO("Object ID [%llu],Offset [%lu], Length [%lu], curr_soze [%lu]",
+       BT_INFO("Object ID [%llu],Offset [%lu], Length [%lu], curr_size [%lu]",
                                                        obj_id, offset, length, object_info->curr_size);
        uint8_t value[9] = {0x00};
 
@@ -1544,7 +1581,7 @@ int bt_otp_client_read_object_contents(bt_otp_client_h otp_client,
        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);
-               otp_client_s->oacp_read_status = FALSE;
+               __bt_otp_reset_api_info(otp_client_s);
        }
 
        return error_code;