447 lines
19 KiB
C
Executable File
447 lines
19 KiB
C
Executable File
#pragma once
|
|
|
|
#include "bk_dm_bluetooth_types.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/// maximum size of HID Device report descriptor
|
|
#define BTHH_MAX_DSC_LEN 884
|
|
|
|
/**
|
|
* @brief HID host connection state
|
|
*/
|
|
typedef enum {
|
|
BK_HIDH_CONN_STATE_CONNECTED = 0, /*!< connected state */
|
|
BK_HIDH_CONN_STATE_CONNECTING, /*!< connecting state */
|
|
BK_HIDH_CONN_STATE_DISCONNECTED, /*!< disconnected state */
|
|
BK_HIDH_CONN_STATE_DISCONNECTING, /*!< disconnecting state */
|
|
BK_HIDH_CONN_STATE_UNKNOWN /*!< unknown state (initial state) */
|
|
} bk_hidh_connection_state_t;
|
|
|
|
/**
|
|
* @brief HID handshake error code and vendor-defined result code
|
|
*/
|
|
typedef enum {
|
|
BK_HIDH_OK, /*!< successful */
|
|
BK_HIDH_HS_HID_NOT_READY, /*!< handshake error: device not ready */
|
|
BK_HIDH_HS_INVALID_RPT_ID, /*!< handshake error: invalid report ID */
|
|
BK_HIDH_HS_TRANS_NOT_SPT, /*!< handshake error: HID device does not support the request */
|
|
BK_HIDH_HS_INVALID_PARAM, /*!< handshake error: parameter value does not meet the expected criteria of called function or API */
|
|
BK_HIDH_HS_ERROR, /*!< handshake error: HID device could not identify the error condition */
|
|
BK_HIDH_ERR, /*!< general BK HID Host error */
|
|
BK_HIDH_ERR_SDP, /*!< SDP error */
|
|
BK_HIDH_ERR_PROTO, /*!< SET_PROTOCOL error, only used in BK_HIDH_OPEN_EVT callback */
|
|
BK_HIDH_ERR_DB_FULL, /*!< device database full, used in BK_HIDH_OPEN_EVT/BK_HIDH_ADD_DEV_EVT */
|
|
BK_HIDH_ERR_TOD_UNSPT, /*!< type of device not supported */
|
|
BK_HIDH_ERR_NO_RES, /*!< out of system resources */
|
|
BK_HIDH_ERR_AUTH_FAILED, /*!< authentication fail */
|
|
BK_HIDH_ERR_HDL, /*!< connection handle error */
|
|
BK_HIDH_ERR_SEC, /*!< encryption error */
|
|
BK_HIDH_BUSY, /*!< vendor-defined: temporarily can not handle this request */
|
|
BK_HIDH_NO_DATA, /*!< vendor-defined: no data. */
|
|
BK_HIDH_NEED_INIT, /*!< vendor-defined: HIDH module shall initialize first */
|
|
BK_HIDH_NEED_DEINIT, /*!< vendor-defined: HIDH module shall de-deinitialize first */
|
|
BK_HIDH_NO_CONNECTION, /*!< vendor-defined: connection may have been closed */
|
|
BK_HIDH_NO_ACL_LINK, /*!< vendor-defined: Baseband acl link not exist */
|
|
} bk_hidh_status_t;
|
|
|
|
/**
|
|
* @brief HID host protocol modes
|
|
*/
|
|
typedef enum {
|
|
BK_HIDH_BOOT_MODE = 0x00, /*!< boot protocol mode */
|
|
BK_HIDH_REPORT_MODE = 0x01, /*!< report protocol mode */
|
|
BK_HIDH_UNSUPPORTED_MODE = 0xff /*!< unsupported protocol mode */
|
|
} bk_hidh_protocol_mode_t;
|
|
|
|
/**
|
|
* @brief HID host report types
|
|
*/
|
|
typedef enum {
|
|
BK_HIDH_REPORT_TYPE_OTHER = 0, /*!< unsupported report type */
|
|
BK_HIDH_REPORT_TYPE_INPUT, /*!< input report type */
|
|
BK_HIDH_REPORT_TYPE_OUTPUT, /*!< output report type */
|
|
BK_HIDH_REPORT_TYPE_FEATURE, /*!< feature report type */
|
|
} bk_hidh_report_type_t;
|
|
|
|
/**
|
|
* @brief HID host callback function events
|
|
*/
|
|
typedef enum {
|
|
BK_HIDH_INIT_EVT = 0, /*!< when HID host is initialized, the event comes */
|
|
BK_HIDH_DEINIT_EVT, /*!< when HID host is deinitialized, the event comes */
|
|
BK_HIDH_OPEN_EVT, /*!< when HID host connection opened, the event comes */
|
|
BK_HIDH_CLOSE_EVT, /*!< when HID host connection closed, the event comes */
|
|
BK_HIDH_GET_RPT_EVT, /*!< when Get_Report command is called, the event comes */
|
|
BK_HIDH_SET_RPT_EVT, /*!< when Set_Report command is called, the event comes */
|
|
BK_HIDH_GET_PROTO_EVT, /*!< when Get_Protocol command is called, the event comes */
|
|
BK_HIDH_SET_PROTO_EVT, /*!< when Set_Protocol command is called, the event comes */
|
|
BK_HIDH_SDP_DSCP_EVT, /*!< when HIDH is connected, the event comes */
|
|
BK_HIDH_ADD_DEV_EVT, /*!< when a device is added, the event comes */
|
|
BK_HIDH_RMV_DEV_EVT, /*!< when a device is removed, the event comes */
|
|
BK_HIDH_VC_UNPLUG_EVT, /*!< when virtually unplugged, the event comes */
|
|
BK_HIDH_DATA_EVT, /*!< when send data on interrupt channel, the event comes */
|
|
BK_HIDH_DATA_IND_EVT, /*!< when receive data on interrupt channel, the event comes */
|
|
BK_HIDH_SET_INFO_EVT /*!< when set the HID device descriptor, the event comes */
|
|
} bk_hidh_cb_event_t;
|
|
|
|
/**
|
|
* @brief HID device information from HID Device Service Record and Device ID Service Record
|
|
*/
|
|
typedef enum {
|
|
BK_HIDH_DEV_ATTR_VIRTUAL_CABLE = 0x0001, /*!< whether Virtual Cables is supported */
|
|
BK_HIDH_DEV_ATTR_RECONNECT_INITIATE = 0x0002, /*!< whether the HID device inititates the reconnection process */
|
|
BK_HIDH_DEV_ATTR_BATTERY_DEVICE = 0x0004, /*!< whether Battery-powered device */
|
|
BK_HIDH_DEV_ATTR_REMOTE_WAKE = 0x0008, /*!< whether wake-up signal to host supported */
|
|
BK_HIDH_DEV_ATTR_NORMALLY_CONNECTABLE = 0x0010, /*!< whether device is in Page Scan mode when there is no active connection */
|
|
BK_HIDH_DEV_ATTR_BOOT_DEVICE = 0x0020, /*!< whether Boot Protocol mode supported */
|
|
} bk_hidh_dev_attr_t;
|
|
|
|
/**
|
|
* @brief application ID(non-zero) for each type of device
|
|
*/
|
|
typedef enum {
|
|
BK_HIDH_APP_ID_MOUSE = 1, /*!< pointing device */
|
|
BK_HIDH_APP_ID_KEYBOARD = 2, /*!< keyboard */
|
|
BK_HIDH_APP_ID_REMOTE_CONTROL = 3, /*!< remote control */
|
|
BK_HIDH_APP_ID_JOYSTICK = 5, /*!< joystick */
|
|
BK_HIDH_APP_ID_GAMEPAD = 6, /*!< gamepad*/
|
|
} bk_hidh_dev_app_id_t;
|
|
|
|
/**
|
|
* @brief HID device information from HID Device Service Record and Device ID Service Record
|
|
*/
|
|
typedef struct {
|
|
int attr_mask; /*!< device attribute bit mask, refer to bk_hidh_dev_attr_t */
|
|
int dl_len; /*!< SDP attrbutes of HID devices: HID device descriptor length */
|
|
uint8_t *dsc_list; /*!< SDP attrbutes of HID devices: HID device descriptor definition */
|
|
} bk_hidh_hid_info_t;
|
|
|
|
/**
|
|
* @brief HID host callback parameters union
|
|
*/
|
|
typedef union {
|
|
/**
|
|
* @brief BK_HIDH_INIT_EVT
|
|
*/
|
|
struct hidh_init_evt_param {
|
|
bk_hidh_status_t status; /*!< status */
|
|
} init; /*!< HIDH callback param of BK_HIDH_INIT_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_DEINIT_EVT
|
|
*/
|
|
struct hidh_uninit_evt_param {
|
|
bk_hidh_status_t status; /*!< status */
|
|
} deinit; /*!< HIDH callback param of BK_HIDH_DEINIT_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_OPEN_EVT
|
|
*/
|
|
struct hidh_open_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
bk_hidh_connection_state_t conn_status; /*!< connection status */
|
|
bool is_orig; /*!< indicate if host intiate the connection */
|
|
uint8_t handle; /*!< device handle */
|
|
bk_bd_addr_t bd_addr; /*!< device address */
|
|
} open; /*!< HIDH callback param of BK_HIDH_OPEN_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_CLOSE_EVT
|
|
*/
|
|
struct hidh_close_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
bk_hidh_connection_state_t conn_status; /*!< connection status */
|
|
uint8_t handle; /*!< device handle */
|
|
} close; /*!< HIDH callback param of BK_HIDH_CLOSE_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_VC_UNPLUG_EVT
|
|
*/
|
|
struct hidh_unplug_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
bk_hidh_connection_state_t conn_status; /*!< connection status */
|
|
uint8_t handle; /*!< device handle */
|
|
} unplug; /*!< HIDH callback param of BK_HIDH_VC_UNPLUG_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_GET_PROTO_EVT
|
|
*/
|
|
struct hidh_get_proto_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
bk_hidh_protocol_mode_t proto_mode; /*!< protocol mode */
|
|
} get_proto; /*!< HIDH callback param of BK_HIDH_GET_PROTO_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_SET_PROTO_EVT
|
|
*/
|
|
struct hidh_set_proto_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
} set_proto; /*!< HIDH callback param of BK_HIDH_SET_PROTO_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_GET_RPT_EVT
|
|
*/
|
|
struct hidh_get_rpt_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
uint16_t len; /*!< data length */
|
|
uint8_t *data; /*!< data pointer */
|
|
} get_rpt; /*!< HIDH callback param of BK_HIDH_GET_RPT_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_SET_RPT_EVT
|
|
*/
|
|
struct hidh_set_rpt_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
} set_rpt; /*!< HIDH callback param of BK_HIDH_SET_RPT_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_DATA_EVT
|
|
*/
|
|
struct hidh_send_data_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
uint8_t reason; /*!< lower layer failed reason */
|
|
} send_data; /*!< HIDH callback param of BK_HIDH_DATA_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_DATA_IND_EVT
|
|
*/
|
|
struct hidh_data_ind_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
bk_hidh_protocol_mode_t proto_mode; /*!< protocol mode */
|
|
uint16_t len; /*!< data length */
|
|
uint8_t *data; /*!< data pointer */
|
|
uint8_t report_type; /*!< report type */
|
|
} data_ind; /*!< HIDH callback param of BK_HIDH_DATA_IND_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_ADD_DEV_EVT
|
|
*/
|
|
struct hidh_add_dev_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
bk_bd_addr_t bd_addr; /*!< device address */
|
|
} add_dev; /*!< HIDH callback param of BK_HIDH_ADD_DEV_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_RMV_DEV_EVT
|
|
*/
|
|
struct hidh_rmv_dev_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
bk_bd_addr_t bd_addr; /*!< device address */
|
|
} rmv_dev; /*!< HIDH callback param of BK_HIDH_RMV_DEV_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_SDP_DSCP_EVT
|
|
*/
|
|
struct hidh_get_dscp_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t sub_class; /*!< HIDDeviceSubclass */
|
|
uint8_t reconn_init; /*!< HIDReconnectInitiate */
|
|
uint8_t normal_conn; /*!< HIDNormallyConnectable */
|
|
uint16_t ssr_max_latency; /*!< SSR max latency in slots */
|
|
uint16_t ssr_min_tout; /*!< SSR min timeout in slots */
|
|
uint8_t ctry_code; /*!< Country Code */
|
|
uint16_t parse_version; /*!< Parse Version*/
|
|
uint8_t virtual_cable; /*!< Virtual Cable */
|
|
uint8_t boot_device; /*!< Boot device*/
|
|
uint8_t remote_wake; /*!< HIDRemoteWake*/
|
|
uint8_t battery_power; /*!< HIDBatteryPower*/
|
|
uint16_t vendor_id; /*!< Device Vendor ID*/
|
|
uint16_t product_id; /*!< Device Product ID*/
|
|
uint16_t device_version; /*!< Device Version*/
|
|
uint16_t dl_len; /*!< Device descriptor length */
|
|
uint8_t *dsc_list; /*!< Device descriptor pointer */
|
|
uint8_t dsc_type; /*!< Device ClassDescriptor type */
|
|
} sdp_dscp; /*!< HIDH callback param of BK_HIDH_GET_DSCP_EVT */
|
|
|
|
/**
|
|
* @brief BK_HIDH_SET_INFO_EVT
|
|
*/
|
|
struct hidh_set_info_evt_param {
|
|
bk_hidh_status_t status; /*!< operation status */
|
|
uint8_t handle; /*!< device handle */
|
|
bk_bd_addr_t bd_addr; /*!< device address */
|
|
} set_info; /*!< HIDH callback param of BK_HIDH_SET_INFO_EVT */
|
|
} bk_hidh_cb_param_t;
|
|
|
|
/**
|
|
* @brief HID host callback function type
|
|
* @param event: Event type
|
|
* @param param: Point to callback parameter, currently is union type
|
|
*/
|
|
typedef void (*bk_hh_cb_t)(bk_hidh_cb_event_t event, bk_hidh_cb_param_t *param);
|
|
|
|
|
|
|
|
/**
|
|
* @brief This function is called to init callbacks with HID host module.
|
|
*
|
|
* @param[in] callback: pointer to the init callback function.
|
|
*
|
|
* @return
|
|
* - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_register_callback(bk_hh_cb_t callback);
|
|
|
|
/**
|
|
* @brief This function initializes HID host. This function should be called after bk_bluetooth_init()
|
|
* success, and should be called after bk_bt_hid_host_register_callback().
|
|
* When the operation is complete the callback function will be called with BK_HIDH_INIT_EVT.
|
|
*
|
|
* @return
|
|
* - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_init(void);
|
|
|
|
/**
|
|
* @brief Closes the interface. This function should be called after bk_bluetooth_init()
|
|
* success, and should be called after bk_bt_hid_host_init().
|
|
* When the operation is complete the callback function will be called with BK_HIDH_DEINIT_EVT.
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_deinit(void);
|
|
|
|
/**
|
|
* @brief Connect to HID device. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_OPEN_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_connect(bk_bd_addr_t bd_addr);
|
|
|
|
/**
|
|
* @brief Disconnect from HID device. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_CLOSE_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_disconnect(bk_bd_addr_t bd_addr);
|
|
|
|
/**
|
|
* @brief Virtual UnPlug (VUP) the specified HID device. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_VC_UNPLUG_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_virtual_cable_unplug(bk_bd_addr_t bd_addr);
|
|
|
|
/**
|
|
* @brief Set the HID device descriptor for the specified HID device. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_SET_INFO_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
* @param[in] hid_info: HID device descriptor structure.
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_set_info(bk_bd_addr_t bd_addr, bk_hidh_hid_info_t *hid_info);
|
|
|
|
/**
|
|
* @brief Get the HID proto mode. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_GET_PROTO_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
*
|
|
* @return
|
|
* - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_get_protocol(bk_bd_addr_t bd_addr);
|
|
|
|
/**
|
|
* @brief Set the HID proto mode. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_SET_PROTO_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
* @param[in] protocol_mode: Protocol mode type.
|
|
*
|
|
* @return
|
|
* - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_set_protocol(bk_bd_addr_t bd_addr, bk_hidh_protocol_mode_t protocol_mode);
|
|
|
|
/**
|
|
* @brief Send a GET_REPORT to HID device. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_GET_RPT_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
* @param[in] report_type: Report type
|
|
* @param[in] report_id: Report id
|
|
* @param[in] buffer_size: Buffer size
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_get_report(bk_bd_addr_t bd_addr, bk_hidh_report_type_t report_type, uint8_t report_id,
|
|
int buffer_size);
|
|
|
|
/**
|
|
* @brief Send a SET_REPORT to HID device. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_SET_RPT_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
* @param[in] report_type: Report type
|
|
* @param[in] report: Report data pointer
|
|
* @param[in] len: Report data length
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_set_report(bk_bd_addr_t bd_addr, bk_hidh_report_type_t report_type, uint8_t *report,
|
|
size_t len);
|
|
|
|
/**
|
|
* @brief Send data to HID device. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_DATA_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
* @param[in] data: Data pointer
|
|
* @param[in] len: Data length
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_send_data(bk_bd_addr_t bd_addr, uint8_t *data, size_t len);
|
|
|
|
/**
|
|
* @brief Start SDP. When the operation is complete the callback
|
|
* function will be called with BK_HIDH_SDP_DSCP_EVT.
|
|
*
|
|
* @param[in] bd_addr: Remote device bluetooth device address.
|
|
*
|
|
* @return - BK_OK: success
|
|
* - other: failed
|
|
*/
|
|
bk_err_t bk_bt_hid_host_sdp_dscp(bk_bd_addr_t bd_addr);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|