1 /* 2 * Copyright (C) 2020 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_HOST_H 39 #define HID_HOST_H 40 41 #include <stdint.h> 42 #include "btstack_defines.h" 43 #include "bluetooth.h" 44 #include "btstack_hid_parser.h" 45 #include "classic/hid.h" 46 47 #if defined __cplusplus 48 extern "C" { 49 #endif 50 51 typedef enum { 52 HID_HOST_IDLE, 53 HID_HOST_W2_SEND_SDP_QUERY, 54 HID_HOST_W4_SDP_QUERY_RESULT, 55 56 HID_HOST_W4_CONTROL_CONNECTION_ESTABLISHED, 57 HID_HOST_CONTROL_CONNECTION_ESTABLISHED, 58 59 HID_HOST_W4_SET_BOOT_MODE, 60 HID_HOST_W4_INTERRUPT_CONNECTION_ESTABLISHED, 61 HID_HOST_CONNECTION_ESTABLISHED, 62 63 HID_HOST_W2_SEND_GET_REPORT, 64 HID_HOST_W4_GET_REPORT_RESPONSE, 65 HID_HOST_W2_SEND_SET_REPORT, 66 HID_HOST_W4_SET_REPORT_RESPONSE, 67 HID_HOST_W2_SEND_GET_PROTOCOL, 68 HID_HOST_W4_GET_PROTOCOL_RESPONSE, 69 HID_HOST_W2_SEND_SET_PROTOCOL, 70 HID_HOST_W4_SET_PROTOCOL_RESPONSE, 71 HID_HOST_W2_SEND_REPORT, 72 HID_HOST_W4_SEND_REPORT_RESPONSE 73 } hid_host_state_t; 74 75 typedef struct { 76 uint16_t hid_cid; 77 hci_con_handle_t con_handle; 78 79 bd_addr_t remote_addr; 80 bool incoming; 81 bool boot_mode; 82 83 uint16_t control_cid; 84 uint16_t control_psm; 85 uint16_t interrupt_cid; 86 uint16_t interrupt_psm; 87 88 hid_host_state_t state; 89 hid_protocol_mode_t protocol_mode; 90 bool unplugged; 91 92 uint16_t hid_descriptor_offset; 93 uint16_t hid_descriptor_len; 94 uint16_t hid_descriptor_max_len; 95 96 uint8_t user_request_can_send_now; 97 98 // get report 99 hid_report_type_t report_type; 100 uint8_t report_id; 101 102 // set report 103 uint8_t * report; 104 uint16_t report_len; 105 } hid_host_connection_t; 106 107 /* API_START */ 108 /** 109 * @brief Set up HID Host 110 * @param boot_protocol_mode_supported 111 * @param hid_descriptor_storage 112 * @param hid_descriptor_storage_len 113 */ 114 void hid_host_init(uint8_t * hid_descriptor_storage, uint16_t hid_descriptor_storage_len); 115 116 /** 117 * @brief Register callback for the HID Device Host. 118 * @param callback 119 */ 120 void hid_host_register_packet_handler(btstack_packet_handler_t callback); 121 122 /* 123 * @brief Create HID connection to HID Host 124 * @param remote_addr 125 * @param hid_cid to use for other commands 126 * @result status 127 */ 128 uint8_t hid_host_connect(bd_addr_t remote_addr, hid_protocol_mode_t protocol_mode, uint16_t * hid_cid); 129 130 /* 131 * @brief Disconnect from HID Host 132 * @param hid_cid 133 */ 134 void hid_host_disconnect(uint16_t hid_cid); 135 136 /** 137 * @brief Request can send now event to send HID Report 138 * Generates an HID_SUBEVENT_CAN_SEND_NOW subevent 139 * @param hid_cid 140 */ 141 void hid_host_request_can_send_now_event(uint16_t hid_cid); 142 143 /** 144 * @brief Send HID message on interrupt channel 145 * @param hid_cid 146 */ 147 void hid_host_send_interrupt_message(uint16_t hid_cid, const uint8_t * message, uint16_t message_len); 148 149 /** 150 * @brief Send HID message on control channel 151 * @param hid_cid 152 */ 153 void hid_host_send_control_message(uint16_t hid_cid, const uint8_t * message, uint16_t message_len); 154 155 156 157 /* API_END */ 158 159 160 #if defined __cplusplus 161 } 162 #endif 163 164 #endif 165