From: paras.kumar Date: Thu, 26 Nov 2015 04:30:55 +0000 (+0530) Subject: Merge/Sync code for HID device role X-Git-Tag: submit/tizen_mobile/20151224.052004~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=30c8b89dd37fb42dba8d1632b35f2682d5fc084a;p=platform%2Fcore%2Fapi%2Fbluetooth.git Merge/Sync code for HID device role Change-Id: I670a6817d317afb9547d924ce24f783910cec7e9 Signed-off-by: paras.kumar --- diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h old mode 100755 new mode 100644 index 1ec4986..48efdc5 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -2969,6 +2969,203 @@ int bt_panu_disconnect(const char *remote_address); int bt_device_le_conn_update(const char *device_address, const bt_le_conn_update_s *parameters); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Registers the method for HID Device role + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks This function must be called to register HID UUID + * then only remote device could be able identify this one as HID device + * + * @param[in] callback The callback called when the connection state is changed + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOW_IN_PROGRESS Already activated + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_hid_device_deactivate() + */ +int bt_hid_device_activate(bt_hid_device_connection_state_changed_cb callback, void * user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Unregisters the method for HID Device role + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks This function must be called to deregister HID UUID + * + * @param[in] socket_fd on which uuid need to be deregistered. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Not activated + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_hid_device_activate() + */ +int bt_hid_device_deactivate(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Initiates HID device Connection with device role + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @remarks This function must be called to Initiate Hid device role connection + * + * @param[in] remote_address device address of remote device. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_NOT_IN_PROGRESS Not activated + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_ALREADY_DONE Already connected + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_hid_device_activate() + */ +int bt_hid_device_connect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Disconnects the connection with HID Host device. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address device address of remote device. + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * @see bt_initialize() + * @see bt_hid_device_connection_state_changed_cb() + */ +int bt_hid_device_disconnect(const char *remote_address); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Sends the mouse event data. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address device address of remote device. + * @param[in] mouse_data mouse data that need to be passed to remote device + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The HID connection must be established. + * @see bt_hid_device_connection_state_changed_cb() + */ +int bt_hid_device_send_mouse_event(const char *remote_address, + const bt_hid_mouse_data_s *mouse_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Sends the keyboard event data. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address device address of remote device. + * @param[in] key_data key data the need to be passed to remote device + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The HID connection must be established. + * @see bt_hid_device_connection_state_changed_cb() + */ +int bt_hid_device_send_key_event(const char *remote_address, + const bt_hid_key_data_s *key_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Sets the callback when device gets some data from HID Host. + * @since_tizen 2.3.1 + * + * @param[in] callback callback function to be set when data is received. + * @param[in] user_data data from application which will be provided in callback. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * + * @see bt_hid_device_connection_state_changed_cb() + */ +int bt_hid_device_set_data_received_cb(bt_hid_device_data_received_cb callback, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Unsets the callback when device gets some data from HID Host. + * @since_tizen 2.3.1 + * + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * + * @see bt_hid_device_connection_state_changed_cb() + */ +int bt_hid_device_unset_data_received_cb(void); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Responds to the reports from HID Host. + * @since_tizen 2.3.1 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address device address of remote device. + * @param[in] htype Header type to be there in response + * @param[in] ptype Parameter type to be there in response. + * @param[in] data Data to be present in data payload of response. + * @param[in] data_len The length of the response data + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * + * @pre The HID connection must be established. + * @see bt_hid_device_connection_state_changed_cb() + */ +int bt_hid_device_reply_to_report(const char *remote_address, + bluetooth_hid_header_type_t htype, bluetooth_hid_param_type_t ptype, + const char *data, unsigned int data_len); + /** * @} */ diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index 8e00a43..79ffd13 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -453,56 +453,6 @@ const GSList* _bt_gatt_get_server_list(void); int _bt_gatt_client_update_all(bt_gatt_client_h client); -/* HID device related type */ -typedef struct -{ - unsigned char btcode; - unsigned char rep_id; - unsigned char button; - signed char axis_x; - signed char axis_y; - signed char axis_z; -} bt_hid_mouse_data_s; - -typedef struct -{ - unsigned char btcode; - unsigned char rep_id; - unsigned char modify; - unsigned char key[8]; -} bt_hid_key_data_s; - -typedef enum { - BT_HID_HEADER_HANDSHAKE, - BT_HID_HEADER_HID_CONTROL, - BT_HID_HEADER_GET_REPORT, - BT_HID_HEADER_SET_REPORT, - BT_HID_HEADER_GET_PROTOCOL, - BT_HID_HEADER_SET_PROTOCOL, - BT_HID_HEADER_DATA, - BT_HID_HEADER_UNKNOWN -} bluetooth_hid_header_type_t; - -typedef enum { - BT_HID_PARAM_DATA_RTYPE_INPUT, - BT_HID_PARAM_DATA_RTYPE_OUTPUT -} bluetooth_hid_param_type_t; - -typedef struct -{ - const char *address; - bluetooth_hid_header_type_t type; - bluetooth_hid_param_type_t param; - int data_size; /**< The length of the received data */ - const char *data; /**< The received data */ -} bt_hid_device_received_data_s; - -typedef void (*bt_hid_device_connection_state_changed_cb) (int result, - bool connected, const char *remote_address, void *user_data); - -typedef void (*bt_hid_device_data_received_cb)(const bt_hid_device_received_data_s *data, void *user_data); -/* HID device related type */ - #ifdef __cplusplus } #endif diff --git a/include/bluetooth_type.h b/include/bluetooth_type.h index 8d5890f..fa90297 100644 --- a/include/bluetooth_type.h +++ b/include/bluetooth_type.h @@ -685,6 +685,47 @@ typedef enum { BT_PANU_SERVICE_TYPE_NAP = 0, /**< Network Access Point */ } bt_panu_service_type_e; +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Enumerations for the types of HID header type + * @since_tizen 3.0 + */ +typedef enum { + BT_HID_HEADER_HANDSHAKE, + BT_HID_HEADER_HID_CONTROL, + BT_HID_HEADER_GET_REPORT, + BT_HID_HEADER_SET_REPORT, + BT_HID_HEADER_GET_PROTOCOL, + BT_HID_HEADER_SET_PROTOCOL, + BT_HID_HEADER_DATA, + BT_HID_HEADER_UNKNOWN +} bluetooth_hid_header_type_t; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Enumerations for the types of HID param type + * @since_tizen 3.0 + */ +typedef enum { + BT_HID_PARAM_DATA_RTYPE_INPUT, + BT_HID_PARAM_DATA_RTYPE_OUTPUT +} bluetooth_hid_param_type_t; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Enumerations for the types of HID handshake type + * @since_tizen 3.0 + */ +typedef enum { + BT_HID_HANDSHAKE_SUCCESSFUL = 0x00, /**< Handshake error code none */ + BT_HID_HANDSHAKE_NOT_READY, /**< Handshake error code Not Ready */ + BT_HID_HANDSHAKE_ERR_INVALID_REPORT_ID, /**< Handshake error code send invalid report id */ + BT_HID_HANDSHAKE_ERR_UNSUPPORTED_REQUEST, /**< Handshake error code request unsupported request */ + BT_HID_HANDSHAKE_ERR_INVALID_PARAMETER, /**< Handshake error code received invalid parameter */ + BT_HID_HANDSHAKE_ERR_UNKNOWN = 0x0e, /**< unkown error */ + BT_HID_HANDSHAKE_ERR_FATAL /**< Fatal error */ +} bluetooth_hid_handshake_type_t; + /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief The handle to control Bluetooth LE advertising @@ -932,6 +973,74 @@ typedef struct char *data; /**< The received data */ } bt_socket_received_data_s; +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief HID Mouse data type; used to send mouse event + * @since_tizen 3.0 + * + * @see bt_hid_device_send_mouse_event() + */ +typedef struct +{ + unsigned char btcode; + unsigned char rep_id; + unsigned char button; + signed char axis_x; + signed char axis_y; + signed char axis_z; +} bt_hid_mouse_data_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief HID Key data; used to send HID key event + * @since_tizen 3.0 + * + * @see bt_hid_device_send_key_event() + */ +typedef struct +{ + unsigned char btcode; + unsigned char rep_id; + unsigned char modify; + unsigned char key[8]; +} bt_hid_key_data_s; + +typedef struct +{ + const char *address; + bluetooth_hid_header_type_t type; + bluetooth_hid_param_type_t param; + int data_size; /**< The length of the received data */ + const char *data; /**< The received data */ +} bt_hid_device_received_data_s; + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Called when the HID Device connection state changes. + * @since_tizen 3.0 + * + * @param[in] result The result of the HID device state changing + * @param[in] connected Whether the device is connected + * @param[in] user_data The user data passed from the callback registration function + * + * @see bt_hid_device_activate() + */ +typedef void (*bt_hid_device_connection_state_changed_cb) (int result, + bool connected, const char *remote_address, void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_HID_MODULE + * @brief Called when any data is received from host device. + * @since_tizen 3.0 + * + * @param[in] data The callback to be set/called upon data receive + * @param[in] user_data The user data passed from the callback registration function + * + * @see bt_hid_device_set_data_received_cb() + */ +typedef void (*bt_hid_device_data_received_cb)(const bt_hid_device_received_data_s *data, + void *user_data); + /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE * @brief Called when the Bluetooth adapter state changes. diff --git a/src/bluetooth-hid.c b/src/bluetooth-hid.c index c84059e..0d634d6 100644 --- a/src/bluetooth-hid.c +++ b/src/bluetooth-hid.c @@ -24,6 +24,7 @@ #include "bluetooth.h" #include "bluetooth_private.h" +#include "bluetooth_internal.h" static bool is_hid_host_initialized = false; @@ -205,6 +206,7 @@ int bt_hid_device_connect(const char *remote_address) int error; BT_CHECK_HID_DEVICE_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); BT_DBG("+"); error = bluetooth_hid_device_connect(remote_address); error = _bt_get_error_code(error); @@ -219,6 +221,7 @@ int bt_hid_device_disconnect(const char *remote_address) int error; BT_CHECK_HID_DEVICE_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); error = bluetooth_hid_device_disconnect(remote_address); error = _bt_get_error_code(error); if (error != BT_ERROR_NONE) @@ -232,6 +235,8 @@ int bt_hid_device_send_mouse_event(const char *remote_address, int ret; BT_CHECK_HID_DEVICE_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + BT_CHECK_INPUT_PARAMETER(mouse_data); ret = bluetooth_hid_device_send_mouse_event(remote_address, *(hid_send_mouse_event_t*)mouse_data); @@ -261,6 +266,8 @@ int bt_hid_device_send_key_event(const char *remote_address, int ret; BT_CHECK_HID_DEVICE_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + BT_CHECK_INPUT_PARAMETER(key_data); ret = bluetooth_hid_device_send_key_event(remote_address, *(hid_send_key_event_t*)key_data); @@ -292,6 +299,8 @@ int bt_hid_device_reply_to_report(const char *remote_address, int ret; BT_CHECK_HID_DEVICE_SUPPORT(); BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + ret = bluetooth_hid_device_reply_to_report(remote_address, htype, ptype, data, data_len); if (ret <= 0) { @@ -323,7 +332,7 @@ int bt_hid_device_set_data_received_cb(bt_hid_device_data_received_cb callback, return BT_ERROR_NONE; } -int bt_hid_device_unset_data_received_cb() +int bt_hid_device_unset_data_received_cb(void) { BT_CHECK_HID_DEVICE_SUPPORT(); BT_CHECK_INIT_STATUS(); diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index fc05865..9bd8fc6 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -416,6 +416,14 @@ tc_table_t tc_hid[] = { {"bt_hid_host_deinitialize" , BT_UNIT_TEST_FUNCTION_HID_HOST_DEINITIALIZE}, {"bt_hid_host_connect" , BT_UNIT_TEST_FUNCTION_HID_HOST_CONNECT}, {"bt_hid_host_disconnect" , BT_UNIT_TEST_FUNCTION_HID_HOST_DISCONNECT}, + {"bt_hid_device_activate" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_ACTIVATE}, + {"bt_hid_device_connect" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_CONNECT}, + {"bt_hid_device_disconnect" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_DISCONNECT}, + {"bt_hid_device_deactivate" , BT_UNIT_TEST_FUCNTION_HID_DEVICE_DEACTIVATE}, + {"bt_hid_device_send_mouse_event" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_MOUSE_EVENT}, + {"bt_hid_device_send_key_event" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_KEY_EVENT}, + {"bt_hid_device_set_data_received_cb " , BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB}, + {"bt_hid_device_unset_data_received_cd" , BT_UNIT_TEST_FUNCTION_HID_DEVICE_UNSET_DATA_RECEIVED_CB}, {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, {NULL , 0x0000}, }; @@ -1025,6 +1033,85 @@ static void __bt_socket_data_received_cb(bt_socket_received_data_s *data, void * TC_PRT("Size: %d", data->data_size); } +static void __bt_hid_device_data_received_cb(const bt_hid_device_received_data_s *data, void *user_data) +{ + TC_PRT("+"); + char val = 0x01; + int ret = 0; + if (data == NULL) { + TC_PRT("No received data"); + return; + } + TC_PRT("Address: %s", data->address); + TC_PRT("Type: %d", data->type); + TC_PRT("Param: %d", data->param); + switch(data->type) { + case BT_HID_HEADER_HANDSHAKE: + TC_PRT("HANDSHAKE data"); + break; + case BT_HID_HEADER_HID_CONTROL: + TC_PRT("HID Control data"); + ret = bt_hid_device_disconnect(remote_addr); + TC_PRT("ret %d", ret); + break; + case BT_HID_HEADER_GET_REPORT: + TC_PRT("GET_REPORT data"); + TC_PRT("ReportId %d", data->data[1]); + bt_hid_key_data_s send_data; + /* Will send character 'a' */ + char pressedkey[8] = { 4, 0, 0, 0, 0, 0, 0, 0 }; + memcpy(send_data.key, pressedkey, 8); + send_data.modify = 0; + if (data->data[1] == 0x02) { + ret = bt_hid_device_reply_to_report(remote_addr,BT_HID_HEADER_GET_REPORT, + BT_HID_PARAM_DATA_RTYPE_INPUT, + (const char*)&send_data, sizeof(send_data)); + } else if (data->data[1] == 0x01) { + TC_PRT("Send Mouse Event"); + } else { + TC_PRT("Invalid ReportId"); + val = BT_HID_HANDSHAKE_ERR_INVALID_REPORT_ID; + ret = bt_hid_device_reply_to_report(remote_addr,BT_HID_HEADER_HANDSHAKE, + BT_HID_PARAM_DATA_RTYPE_INPUT, + &val, sizeof(val)); + } + TC_PRT("ret %d", ret); + break; + case BT_HID_HEADER_SET_REPORT: + TC_PRT("SET_REPORT data"); + break; + case BT_HID_HEADER_DATA: + TC_PRT("TRANs DATA"); + break; + case BT_HID_HEADER_GET_PROTOCOL: + TC_PRT("GET PROTOCOL"); + ret = bt_hid_device_reply_to_report(remote_addr,BT_HID_HEADER_GET_PROTOCOL, + BT_HID_PARAM_DATA_RTYPE_INPUT, + &val, sizeof(val)); + TC_PRT("ret %d", ret); + break; + case BT_HID_HEADER_SET_PROTOCOL: + TC_PRT("SET PROTOCOL"); + val = BT_HID_HANDSHAKE_SUCCESSFUL; + ret = bt_hid_device_reply_to_report(remote_addr,BT_HID_HEADER_HANDSHAKE, + BT_HID_PARAM_DATA_RTYPE_INPUT, + &val, sizeof(val)); + TC_PRT("ret %d", ret); + break; + default: + TC_PRT("Unkonw"); + break; + } + switch(data->param) { + case BT_HID_PARAM_DATA_RTYPE_INPUT: + TC_PRT("Input Report"); + break; + case BT_HID_PARAM_DATA_RTYPE_OUTPUT: + TC_PRT("Output Report"); + break; + } +} + static void __bt_socket_connection_requested_cb(int socket_fd, const char *remote_address, void *user_data) { TC_PRT("Socket fd: %d", socket_fd); @@ -1714,6 +1801,15 @@ void __bt_hid_host_connection_state_changed_cb(int result, TC_PRT("result: %s", __bt_get_error_message(result)); } +void __bt_hid_device_connection_state_changed_cb(int result, + bool connected, const char *remote_address, void *user_data) +{ + TC_PRT("__bt_hid_device_connection_state_changed_cb:"); + TC_PRT("result: %s", __bt_get_error_message(result)); + TC_PRT("Remote Address %s", remote_address); + TC_PRT("Connected %d", connected); +} + #ifdef TIZEN_WEARABLE void __bt_hf_sco_state_changed_cb(int result, bool opened, void *user_data) { @@ -5091,6 +5187,118 @@ int test_input_callback(void *data) TC_PRT("returns %s\n", __bt_get_error_message(ret)); break; } + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_ACTIVATE: { + ret = bt_hid_device_activate(__bt_hid_device_connection_state_changed_cb, + NULL); + TC_PRT("returns %s", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_CONNECT: { + ret = bt_hid_device_connect(remote_addr); + TC_PRT("returns %s", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUCNTION_HID_DEVICE_DEACTIVATE: { + ret = bt_hid_device_deactivate(); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_DISCONNECT: { + ret = bt_hid_device_disconnect(remote_addr); + TC_PRT("return %s", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_MOUSE_EVENT: { + bt_hid_mouse_data_s send_data; + int i; + + send_data.button = 1; + send_data.axis_z = 0x00; + + send_data.axis_x = 10; + send_data.axis_y = 0; + for (i = 0; i < 30; i++) { + usleep(30000); + ret = bt_hid_device_send_mouse_event(remote_addr,&send_data); + if (ret < 0) + TC_PRT("returns %d\n", ret); + } + send_data.axis_x = 0; + send_data.axis_y = 10; + for (i = 0; i < 30; i++) { + usleep(30000); + ret = bt_hid_device_send_mouse_event(remote_addr,&send_data); + if (ret < 0) + TC_PRT("returns %d\n", ret); + } + send_data.axis_x = -10; + send_data.axis_y = 0; + for (i = 0; i < 60; i++) { + usleep(30000); + ret = bt_hid_device_send_mouse_event(remote_addr,&send_data); + if (ret < 0) + TC_PRT("returns %d\n", ret); + } + send_data.axis_x = 0; + send_data.axis_y = -10; + for (i = 0; i < 60; i++) { + usleep(30000); + ret = bt_hid_device_send_mouse_event(remote_addr,&send_data); + if (ret < 0) + TC_PRT("returns %d\n", ret); + } + send_data.axis_x = 10; + send_data.axis_y = 0; + for (i = 0; i < 60; i++) { + usleep(30000); + ret = bt_hid_device_send_mouse_event(remote_addr,&send_data); + if (ret < 0) + TC_PRT("returns %d\n", ret); + } + send_data.axis_x = 0; + send_data.axis_y = 10; + for (i = 0; i < 30; i++) { + usleep(30000); + ret = bt_hid_device_send_mouse_event(remote_addr,&send_data); + if (ret < 0) + TC_PRT("returns %d\n", ret); + } + send_data.axis_x = -10; + send_data.axis_y = 0; + for (i = 0; i < 30; i++) { + usleep(30000); + ret = bt_hid_device_send_mouse_event(remote_addr,&send_data); + if (ret < 0) + TC_PRT("returns %d\n", ret); + } + TC_PRT("Completed"); + + break; + } + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SEND_KEY_EVENT: { + bt_hid_key_data_s send_data; + /* Will send character 'a' */ + char pressedkey[8] = { 4, 0, 0, 0, 0, 0, 0, 0 }; + char pressedkey1[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; + memcpy(send_data.key, pressedkey, 8); + send_data.modify = 0; + ret = bt_hid_device_send_key_event(remote_addr,&send_data); + TC_PRT("returns %d\n", ret); + memcpy(send_data.key, pressedkey1, 8); + ret = bt_hid_device_send_key_event(remote_addr,&send_data); + TC_PRT("returns %d\n", ret); + break; + } + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_SET_DATA_RECEIVED_CB: { + ret = bt_hid_device_set_data_received_cb(__bt_hid_device_data_received_cb, NULL); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_HID_DEVICE_UNSET_DATA_RECEIVED_CB: { + ret = bt_hid_device_unset_data_received_cb(); + 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");