From: DoHyun Pyun Date: Mon, 27 Aug 2018 02:26:57 +0000 (+0900) Subject: Reduce the complexity of _bt_otp_client_indication function X-Git-Tag: submit/tizen/20180827.065630~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=16615724c85f46011106bd119d35d15678540380;p=platform%2Fcore%2Fapi%2Fbluetooth.git Reduce the complexity of _bt_otp_client_indication function Change-Id: I1e5b45fe62e25245105aa0b2a75e70a527826e37 Signed-off-by: DoHyun Pyun --- diff --git a/src/bluetooth-otp.c b/src/bluetooth-otp.c index 82b9fa6..bf8b2b1 100644 --- a/src/bluetooth-otp.c +++ b/src/bluetooth-otp.c @@ -1435,197 +1435,220 @@ void _bt_otp_client_notification_enabled(int result, char *handle) } } -void _bt_otp_client_indication(int result, bluetooth_otp_resp_info_t *info) +static void __bt_otp_oacp_control_indication(int result, bt_otp_client_s *otp_client_s, bluetooth_otp_resp_info_t *info) { - bt_otp_client_s *otp_client_s = NULL; - char remote_address[BT_ADDR_LENGTH]; + uint8_t resp_code = info->data[0]; + uint8_t req_opcode = info->data[1]; + uint8_t result_code = info->data[2]; int error_code; - BT_DBG("OTP indication response [%s]", info->handle); - _bt_otp_get_remote_address(info->handle, remote_address); + /* Indication failed/timeout occured */ + if (result != BLUETOOTH_ERROR_NONE) + goto oacp_done; - otp_client_s = _bt_otp_client_find(remote_address); - if (otp_client_s == NULL) { - BT_INFO("Client Not Found"); - return; + BT_INFO("Resp_code [0x%x], Req_opcode [0x%x], result_code [0x%x]", + resp_code, req_opcode, result_code); + + if (resp_code != OACP_RESPONSE) { + BT_INFO("Indication Response Failed : Wrong Response Code"); + result = BLUETOOTH_ERROR_INTERNAL; + goto oacp_done; } - if (!g_strcmp0(otp_client_s->otp_oacp_control_point, info->handle)) { - uint8_t resp_code = info->data[0]; - uint8_t req_opcode = info->data[1]; - uint8_t result_code = info->data[2]; + if (result_code != OACP_SUCCESS) { + BT_INFO("Indication Response Fail [0x%x]", result_code); + result = BLUETOOTH_ERROR_INTERNAL; + goto oacp_done; + } - BT_INFO("Resp_code [0x%x], Req_opcode [0x%x], result_code [0x%x]", - resp_code, req_opcode, result_code); + switch (req_opcode) { + case OACP_CREATE: + BT_INFO("OACP_CREATE Indication received"); + if ((otp_client_s->curr_op == BT_OTP_OBJECT_CREATE) && oacp_create_op) { + int len; + uint8_t value[BT_FILE_PATH_MAX_LEN]; - if (resp_code != OACP_RESPONSE) { - BT_INFO("Indication Response Failed : Wrong Response Code"); - result = BLUETOOTH_ERROR_INTERNAL; - goto oacp_done; + len = strlen(oacp_create_op->filename) + 1; + memcpy(value, oacp_create_op->filename, len); + + error_code = bluetooth_otp_write_characteristics_value(otp_client_s->otp_name_obj_path, + value, len); + if (error_code != BT_ERROR_NONE) { + BT_ERR("Failed to write object name : %s(0x%08x)", + _bt_convert_error_to_string(error_code), error_code); + result = error_code; + goto oacp_done; + } + } + break; + case OACP_DELETE: + BT_INFO("OACP_DELETE Indication received"); + goto oacp_done; + break; + case OACP_CALC_CHECKSUM: + break; + case OACP_EXECUTE: + BT_INFO("OACP_EXECUTE Indication received"); + goto oacp_done; + break; + case OACP_READ: + case OACP_WRITE: + { + BT_INFO("OACP Read/Write Indication received"); + bluetooth_device_address_t addr_hex = { {0,} }; + _bt_convert_address_to_hex(&addr_hex, otp_client_s->remote_address); + + if (otc_connection_status) { + BT_INFO("OTC Connected already"); + break; } - if (result_code != OACP_SUCCESS) { - BT_INFO("Indication Response Fail [0x%x]", result_code); - result = BLUETOOTH_ERROR_INTERNAL; + error_code = bluetooth_otp_connect_otc(&addr_hex); + if (error_code != BLUETOOTH_ERROR_NONE) { + BT_INFO("OTC Connection Failed %s(0x%08x)", + _bt_convert_error_to_string(error_code), error_code); + result = error_code; goto oacp_done; } + break; + } + case OACP_ABORT: + break; + default: + BT_INFO("Indication Failed : Wrong Req Opcode [0x%x], Reason [0x%x]", + req_opcode, result_code); + result = BLUETOOTH_ERROR_INTERNAL; + goto oacp_done; + break; + } + return; - switch (req_opcode) { - case OACP_CREATE: - BT_INFO("OACP_CREATE Indication received"); - if ((otp_client_s->curr_op == BT_OTP_OBJECT_CREATE) && oacp_create_op) { - int len; - uint8_t value[BT_FILE_PATH_MAX_LEN]; +oacp_done: + switch (otp_client_s->curr_op) { + case BT_OTP_OBJECT_READ: + case BT_OTP_OBJECT_CREATE: + case BT_OTP_OBJECT_WRITE: + case BT_OTP_OBJECT_EXECUTE: + case BT_OTP_OBJECT_DELETE: + _bt_otp_send_callback(result, NULL, 0, 0, otp_client_s); + break; + default: + break; + } +} - len = strlen(oacp_create_op->filename) + 1; - memcpy(value, oacp_create_op->filename, len); +static void __bt_otp_olcp_control_indication(int result, bt_otp_client_s *otp_client_s, bluetooth_otp_resp_info_t *info) +{ + uint8_t resp_code = info->data[0]; + uint8_t req_opcode = info->data[1]; + uint8_t result_code = info->data[2]; + int error_code; - error_code = bluetooth_otp_write_characteristics_value(otp_client_s->otp_name_obj_path, - value, len); - if (error_code != BT_ERROR_NONE) { - BT_ERR("Failed to write object name : %s(0x%08x)", - _bt_convert_error_to_string(error_code), error_code); - result = error_code; - goto oacp_done; - } - } - break; - case OACP_DELETE: - BT_INFO("OACP_DELETE Indication received"); - goto oacp_done; - break; - case OACP_CALC_CHECKSUM: - break; - case OACP_EXECUTE: - BT_INFO("OACP_EXECUTE Indication received"); - goto oacp_done; - break; - case OACP_READ: - case OACP_WRITE: - { - BT_INFO("OACP Read/Write Indication received"); - bluetooth_device_address_t addr_hex = { {0,} }; - _bt_convert_address_to_hex(&addr_hex, otp_client_s->remote_address); - - if (otc_connection_status) { - BT_INFO("OTC Connected already"); - break; - } + /* Indication failed/timeout occured */ + if (result != BLUETOOTH_ERROR_NONE) + goto olcp_done; - error_code = bluetooth_otp_connect_otc(&addr_hex); - if (error_code != BLUETOOTH_ERROR_NONE) { - BT_INFO("OTC Connection Failed %s(0x%08x)", - _bt_convert_error_to_string(error_code), error_code); - result = error_code; - goto oacp_done; - } + BT_INFO("Resp_code [0x%x], Req_opcode [0x%x], result_code [0x%x]", + resp_code, req_opcode, result_code); + + if (resp_code != OLCP_RESPONSE) { + BT_INFO("Indication Response Failed : Wrong Response Code"); + result = BLUETOOTH_ERROR_INTERNAL; + goto olcp_done; + } + + if (result_code != OLCP_SUCCESS) { + switch (result_code) { + case OLCP_NO_OBJ: + BT_INFO("No Object Found on server"); + result = BLUETOOTH_ERROR_INTERNAL; break; - } - case OACP_ABORT: + case OLCP_OUT_OF_BOUNDS: + /* All object discovered succesfully, notify application via callback */ + result = BLUETOOTH_ERROR_NONE; break; - default: - BT_INFO("Indication Failed : Wrong Req Opcode [0x%x], Reason [0x%x]", - req_opcode, result_code); + case OLCP_OJECT_ID_NOT_FOUND: + BT_INFO("Object ID not found"); result = BLUETOOTH_ERROR_INTERNAL; - goto oacp_done; - break; - } - return; -oacp_done: - switch (otp_client_s->curr_op) { - case BT_OTP_OBJECT_READ: - case BT_OTP_OBJECT_CREATE: - case BT_OTP_OBJECT_WRITE: - case BT_OTP_OBJECT_EXECUTE: - case BT_OTP_OBJECT_DELETE: - _bt_otp_send_callback(result, NULL, 0, 0, otp_client_s); break; default: + BT_INFO("Indication Response Fail [0x%x]", result_code); + result = BLUETOOTH_ERROR_INTERNAL; break; } - } else if (!g_strcmp0(otp_client_s->otp_olcp_control_point, info->handle)) { - uint8_t resp_code = info->data[0]; - uint8_t req_opcode = info->data[1]; - uint8_t result_code = info->data[2]; + goto olcp_done; + } - /* Indication failed/timeout occured */ - if (result != BLUETOOTH_ERROR_NONE) + switch (req_opcode) { + case OLCP_ORDER: + case OLCP_REQ_NO_OBJ: + case OLCP_CLEAR_MARKING: + break; + case OLCP_FIRST: + case OLCP_LAST: + case OLCP_NEXT: + case OLCP_PREVIOUS: { + /* Once we get success indication response for OLCP, + * attempt to read object metadata */ + metadata = g_malloc0(sizeof(object_metadata)); + error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_name_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); + result = error_code; + goto olcp_done; + } + } break; + case OLCP_GOTO: + /* Update the object id & notify client app*/ + otp_client_s->object_id = select_obj_id; + select_obj_id = 0; goto olcp_done; + break; + default: + BT_INFO("Indication Response Failed : Wrong Req Opcode [0x%x], Reason [0x%x]", + req_opcode, result_code); + result = BLUETOOTH_ERROR_INTERNAL; + goto olcp_done; + break; + } + return; - BT_INFO("Resp_code [0x%x], Req_opcode [0x%x], result_code [0x%x]", - resp_code, req_opcode, result_code); +olcp_done: + switch (otp_client_s->curr_op) { + case BT_OTP_OBJECT_DISCOVERY: + case BT_OTP_OBJECT_SELECT: + _bt_otp_send_callback(result, NULL, 0, 0, otp_client_s); + break; + default: + break; + } +} - if (resp_code != OLCP_RESPONSE) { - BT_INFO("Indication Response Failed : Wrong Response Code"); - result = BLUETOOTH_ERROR_INTERNAL; - goto olcp_done; - } +void _bt_otp_client_indication(int result, bluetooth_otp_resp_info_t *info) +{ + bt_otp_client_s *otp_client_s = NULL; + char remote_address[BT_ADDR_LENGTH]; - if (result_code != OLCP_SUCCESS) { - switch (result_code) { - case OLCP_NO_OBJ: - BT_INFO("No Object Found on server"); - result = BLUETOOTH_ERROR_INTERNAL; - break; - case OLCP_OUT_OF_BOUNDS: - /* All object discovered succesfully, notify application via callback */ - result = BLUETOOTH_ERROR_NONE; - break; - case OLCP_OJECT_ID_NOT_FOUND: - BT_INFO("Object ID not found"); - result = BLUETOOTH_ERROR_INTERNAL; - break; - default: - BT_INFO("Indication Response Fail [0x%x]", result_code); - result = BLUETOOTH_ERROR_INTERNAL; - break; - } - goto olcp_done; - } + BT_DBG("OTP indication response [%s]", info->handle); + _bt_otp_get_remote_address(info->handle, remote_address); - switch (req_opcode) { - case OLCP_ORDER: - case OLCP_REQ_NO_OBJ: - case OLCP_CLEAR_MARKING: - break; - case OLCP_FIRST: - case OLCP_LAST: - case OLCP_NEXT: - case OLCP_PREVIOUS: { - /* Once we get success indication response for OLCP, - * attempt to read object metadata */ - metadata = g_malloc0(sizeof(object_metadata)); - error_code = bluetooth_otp_read_characteristic_value(otp_client_s->otp_name_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); - result = error_code; - goto olcp_done; - } - } break; - case OLCP_GOTO: - /* Update the object id & notify client app*/ - otp_client_s->object_id = select_obj_id; - select_obj_id = 0; - goto olcp_done; - break; - default: - BT_INFO("Indication Response Failed : Wrong Req Opcode [0x%x], Reason [0x%x]", - req_opcode, result_code); - result = BLUETOOTH_ERROR_INTERNAL; - goto olcp_done; - break; - } + otp_client_s = _bt_otp_client_find(remote_address); + if (otp_client_s == NULL) { + BT_INFO("Client Not Found"); return; -olcp_done: - switch (otp_client_s->curr_op) { - case BT_OTP_OBJECT_DISCOVERY: - case BT_OTP_OBJECT_SELECT: - _bt_otp_send_callback(result, NULL, 0, 0, otp_client_s); - break; - default: - break; - } - } else if (!g_strcmp0(otp_client_s->otp_obj_changed_obj_path, info->handle)) { + } + + if (!g_strcmp0(otp_client_s->otp_oacp_control_point, info->handle)) { + __bt_otp_oacp_control_indication(result, otp_client_s, info); + return; + } + + if (!g_strcmp0(otp_client_s->otp_olcp_control_point, info->handle)) { + __bt_otp_olcp_control_indication(result, otp_client_s, info); + return; + } + + if (!g_strcmp0(otp_client_s->otp_obj_changed_obj_path, info->handle)) { BT_INFO("Indication Received for Object Changed Characteristic"); uint8_t flag = info->data[0]; uint64_t id = 0; @@ -1642,6 +1665,7 @@ olcp_done: (uint64_t)(info->data[2] & 0xFF) << 8 | (uint64_t)(info->data[1] & 0xFF); BT_INFO("Changed occurred to object id %llu", id); + return; } }