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 #define BTSTACK_FILE__ "hid_host.c" 39 40 #include <string.h> 41 42 #include "bluetooth.h" 43 #include "bluetooth_psm.h" 44 #include "bluetooth_sdp.h" 45 #include "btstack_debug.h" 46 #include "btstack_event.h" 47 #include "btstack_hid_parser.h" 48 #include "classic/hid.h" 49 #include "classic/hid_host.h" 50 #include "classic/sdp_util.h" 51 #include "l2cap.h" 52 53 typedef enum { 54 HID_HOST_IDLE, 55 HID_HOST_CONTROL_CONNECTION_ESTABLISHED, 56 HID_HOST_W4_SET_BOOT_MODE, 57 HID_HOST_W4_INTERRUPT_CONNECTION_ESTABLISHED, 58 HID_HOST_CONNECTION_ESTABLISHED, 59 HID_HOST_W2_SEND_GET_REPORT, 60 HID_HOST_W4_GET_REPORT_RESPONSE, 61 HID_HOST_W2_SEND_SET_REPORT, 62 HID_HOST_W4_SET_REPORT_RESPONSE, 63 HID_HOST_W2_SEND_GET_PROTOCOL, 64 HID_HOST_W4_GET_PROTOCOL_RESPONSE, 65 HID_HOST_W2_SEND_SET_PROTOCOL, 66 HID_HOST_W4_SET_PROTOCOL_RESPONSE, 67 HID_HOST_W2_SEND_REPORT, 68 HID_HOST_W4_SEND_REPORT_RESPONSE 69 } hid_host_state_t; 70 71 typedef struct { 72 uint16_t cid; 73 bd_addr_t bd_addr; 74 hci_con_handle_t con_handle; 75 uint16_t control_cid; 76 uint16_t interrupt_cid; 77 78 hid_host_state_t state; 79 hid_protocol_mode_t protocol_mode; 80 81 uint8_t user_request_can_send_now; 82 83 // get report 84 hid_report_type_t report_type; 85 uint8_t report_id; 86 87 // set report 88 uint8_t * report; 89 uint16_t report_len; 90 } hid_host_connection_t; 91 92 static const uint8_t * hid_host_descriptor_storage; 93 static uint16_t hid_host_descriptor_storage_len; 94 95 static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 96 uint8_t event; 97 // bd_addr_t address; 98 // uint8_t status; 99 // uint16_t l2cap_cid; 100 // hid_host_t * hid_host; 101 // uint8_t param; 102 // hid_message_type_t message_type; 103 // hid_handshake_param_type_t message_status; 104 105 switch (packet_type) { 106 case HCI_EVENT_PACKET: 107 event = hci_event_packet_get_type(packet); 108 switch (event) { 109 case BTSTACK_EVENT_STATE: 110 if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING){ 111 printf("BTstack up and running. \n"); 112 } 113 break; 114 default: 115 break; 116 } 117 default: 118 break; 119 } 120 } 121 122 void hid_host_init(const uint8_t * hid_descriptor_storage, uint16_t hid_descriptor_storage_len){ 123 hid_host_descriptor_storage = hid_descriptor_storage; 124 hid_host_descriptor_storage_len = hid_descriptor_storage_len; 125 126 // register L2CAP Services for reconnections 127 l2cap_register_service(packet_handler, PSM_HID_INTERRUPT, 0xffff, gap_get_security_level()); 128 l2cap_register_service(packet_handler, PSM_HID_CONTROL, 0xffff, gap_get_security_level()); 129 } 130 131 void hid_host_register_packet_handler(btstack_packet_handler_t callback){ 132 UNUSED(callback); 133 } 134 135 uint8_t hid_host_connect(bd_addr_t addr, hid_protocol_mode_t protocol_mode, uint16_t * hid_cid){ 136 UNUSED(hid_cid); 137 UNUSED(protocol_mode); 138 return ERROR_CODE_SUCCESS; 139 } 140 141 142 void hid_host_disconnect(uint16_t hid_cid){ 143 UNUSED(hid_cid); 144 } 145 146 void hid_host_request_can_send_now_event(uint16_t hid_cid){ 147 UNUSED(hid_cid); 148 } 149 150 void hid_host_send_interrupt_message(uint16_t hid_cid, const uint8_t * message, uint16_t message_len){ 151 UNUSED(hid_cid); 152 UNUSED(message); 153 UNUSED(message_len); 154 } 155 156 void hid_host_send_control_message(uint16_t hid_cid, const uint8_t * message, uint16_t message_len){ 157 UNUSED(hid_cid); 158 UNUSED(message); 159 UNUSED(message_len); 160 }