1 /* 2 * Copyright (C) 2014 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 #ifndef __HID_DEVICE_H 39 #define __HID_DEVICE_H 40 41 #include <stdint.h> 42 #include "btstack_defines.h" 43 #include "bluetooth.h" 44 45 #if defined __cplusplus 46 extern "C" { 47 #endif 48 49 /* API_START */ 50 51 #define HID_BOOT_MODE_KEYBOARD_ID 1 52 #define HID_BOOT_MODE_MOUSE_ID 2 53 54 typedef enum { 55 HID_MESSAGE_TYPE_HANDSHAKE = 0, 56 HID_MESSAGE_TYPE_HID_CONTROL, 57 HID_MESSAGE_TYPE_RESERVED_2, 58 HID_MESSAGE_TYPE_RESERVED_3, 59 HID_MESSAGE_TYPE_GET_REPORT, 60 HID_MESSAGE_TYPE_SET_REPORT, 61 HID_MESSAGE_TYPE_GET_PROTOCOL, 62 HID_MESSAGE_TYPE_SET_PROTOCOL, 63 HID_MESSAGE_TYPE_GET_IDLE_DEPRECATED, 64 HID_MESSAGE_TYPE_SET_IDLE_DEPRECATED, 65 HID_MESSAGE_TYPE_DATA, 66 HID_MESSAGE_TYPE_DATC_DEPRECATED 67 } hid_message_type_t; 68 69 typedef enum { 70 HID_HANDSHAKE_PARAM_TYPE_SUCCESSFUL = 0x00, // This code is used to acknowledge requests. A device that has correctly received SET_REPORT, SET_IDLE or SET_PROTOCOL payload transmits an acknowledgment to the host. 71 HID_HANDSHAKE_PARAM_TYPE_NOT_READY, // This code indicates that a device is too busy to accept data. The Bluetooth HID Host should retransmit the data the next time it communicates with the device. 72 HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_REPORT_ID, // Invalid report ID transmitted. 73 HID_HANDSHAKE_PARAM_TYPE_ERR_UNSUPPORTED_REQUEST, // The device does not support the request. This result code shall be used if the HIDP message type is unsupported. 74 HID_HANDSHAKE_PARAM_TYPE_ERR_INVALID_PARAMETER, // A parameter value is out of range or inappropriate for the request. 75 HID_HANDSHAKE_PARAM_TYPE_ERR_UNKNOWN = 0x0E // Device could not identify the error condition. 0xF = ERR_FATAL. Restart is essential to resume functionality. 76 } hid_handshake_param_type_t; 77 78 typedef enum { 79 HID_CONTROL_PARAM_NOP_DEPRECATED = 0, // Deprecated: No Operation. 80 HID_CONTROL_PARAM_HARD_RESET_DEPRECATED, // Deprecated: Device performs Power On System Test (POST) then initializes all internal variables and initiates normal operations. 81 HID_CONTROL_PARAM_SOFT_RESET_DEPRECATED, // Deprecated: Device initializes all internal variables and initiates normal operations. 82 HID_CONTROL_PARAM_SUSPEND = 0x03, // Go to reduced power mode. 83 HID_CONTROL_PARAM_EXIT_SUSPEND, // Exit reduced power mode. 84 HID_CONTROL_PARAM_VIRTUAL_CABLE_UNPLUG 85 } hid_control_param_t; 86 87 typedef enum { 88 HID_REPORT_TYPE_RESERVED = 0, 89 HID_REPORT_TYPE_INPUT, 90 HID_REPORT_TYPE_OUTPUT, 91 HID_REPORT_TYPE_FEATURE 92 } hid_report_type_t; 93 94 typedef enum { 95 HID_PROTOCOL_MODE_BOOT = 0, 96 HID_PROTOCOL_MODE_REPORT 97 } hid_protocol_mode_t; 98 99 typedef enum { 100 HID_REPORT_ID_UNDECLARED, 101 HID_REPORT_ID_VALID, 102 HID_REPORT_ID_INVALID 103 } hid_report_id_status_t; 104 105 /** 106 * @brief Create HID Device SDP service record. 107 * @param service Empty buffer in which a new service record will be stored. 108 * @param have_remote_audio_control 109 * @param service 110 * @param service_record_handle 111 * @param hid_device_subclass 112 * @param hid_country_code 113 * @param hid_virtual_cable 114 * @param hid_reconnect_initiate 115 * @param hid_boot_device 116 * @param hid_descriptor 117 * @param hid_descriptor_size size of hid_descriptor 118 * @param device_name 119 */ 120 void hid_create_sdp_record( 121 uint8_t * service, 122 uint32_t service_record_handle, 123 uint16_t hid_device_subclass, 124 uint8_t hid_country_code, 125 uint8_t hid_virtual_cable, 126 uint8_t hid_reconnect_initiate, 127 uint8_t hid_boot_device, 128 const uint8_t * hid_descriptor, 129 uint16_t hid_descriptor_size, 130 const char * device_name); 131 132 133 /** 134 * @brief Set up HID Device 135 * @param boot_protocol_mode_supported 136 */ 137 void hid_device_init(uint8_t boot_protocol_mode_supported, uint8_t report_ids_declared); 138 139 /** 140 * @brief Register callback for the HID Device client. 141 * @param callback 142 */ 143 void hid_device_register_packet_handler(btstack_packet_handler_t callback); 144 145 /** 146 * @brief Register get report callback for the HID Device client. 147 * @param callback 148 */ 149 void hid_device_register_report_request_callback(hid_handshake_param_type_t (*callback) (uint16_t hid_cid, hid_report_type_t report_type, uint16_t report_id, uint8_t report_max_size, int * out_report_size, uint8_t * out_report)); 150 151 /** 152 * @brief Register set report callback for the HID Device client. 153 * @param callback 154 */ 155 void hid_device_register_set_report_callback(hid_handshake_param_type_t (*callback) (uint16_t hid_cid, hid_report_type_t report_type, int report_size, uint8_t * report)); 156 157 /** 158 * @brief Register callback to receive report data for the HID Device client. 159 * @param callback 160 */ 161 void hid_device_register_report_data_callback(void hid_report_data_callback(uint16_t cid, hid_report_type_t report_type, uint16_t report_id, int report_size, uint8_t * report)); 162 163 /* 164 * @brief Create HID connection to HID Host 165 * @param addr 166 * @param hid_cid to use for other commands 167 * @result status 168 */ 169 uint8_t hid_device_connect(bd_addr_t addr, uint16_t * hid_cid); 170 171 /* 172 * @brief Disconnect from HID Host 173 * @param hid_cid 174 */ 175 void hid_device_disconnect(uint16_t hid_cid); 176 177 /** 178 * @brief Request can send now event to send HID Report 179 * Generates an HID_SUBEVENT_CAN_SEND_NOW subevent 180 * @param hid_cid 181 */ 182 void hid_device_request_can_send_now_event(uint16_t hid_cid); 183 184 /** 185 * @brief Send HID messageon interrupt channel 186 * @param hid_cid 187 */ 188 void hid_device_send_interrupt_message(uint16_t hid_cid, const uint8_t * message, uint16_t message_len); 189 190 /** 191 * @brief Send HID messageon control channel 192 * @param hid_cid 193 */ 194 void hid_device_send_control_message(uint16_t hid_cid, const uint8_t * message, uint16_t message_len); 195 196 /** 197 * @brief Retutn 1 if boot protocol mode active 198 * @param hid_cid 199 */ 200 int hid_device_in_boot_protocol_mode(uint16_t hid_cid); 201 202 /* API_END */ 203 204 /* Only needed for PTS Testing */ 205 void hid_device_disconnect_interrupt_channel(uint16_t hid_cid); 206 void hid_device_disconnect_control_channel(uint16_t hid_cid); 207 208 #if defined __cplusplus 209 } 210 #endif 211 212 #endif 213