1 /* 2 * Copyright (C) 2021 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 HIDS_CLIENT_H 39 #define HIDS_CLIENT_H 40 41 #if defined __cplusplus 42 extern "C" { 43 #endif 44 45 #include <stdint.h> 46 #include "hid.h" 47 #include "btstack_defines.h" 48 #include "bluetooth.h" 49 #include "btstack_linked_list.h" 50 #include "ble/gatt_client.h" 51 52 #ifndef MAX_NUM_HID_SERVICES 53 #define MAX_NUM_HID_SERVICES 3 54 #endif 55 56 typedef enum { 57 HIDS_CLIENT_STATE_IDLE, 58 HIDS_CLIENT_STATE_W2_QUERY_SERVICE, 59 HIDS_CLIENT_STATE_W4_SERVICE_RESULT, 60 HIDS_CLIENT_STATE_W2_QUERY_CHARACTERISTIC, 61 HIDS_CLIENT_STATE_W4_CHARACTERISTIC_RESULT, 62 HIDS_CLIENT_STATE_CONNECTED 63 } hid_service_client_state_t; 64 65 66 typedef struct { 67 // service 68 uint16_t start_handle; 69 uint16_t end_handle; 70 71 } hid_service_t; 72 73 74 typedef struct { 75 btstack_linked_item_t item; 76 77 hci_con_handle_t con_handle; 78 uint16_t cid; 79 hid_service_client_state_t state; 80 btstack_packet_handler_t client_handler; 81 82 uint8_t num_instances; 83 hid_service_t services[MAX_NUM_HID_SERVICES]; 84 } hids_client_t; 85 86 /* API_START */ 87 88 /** 89 * @brief Initialize Battery Service. 90 */ 91 void hids_client_init(void); 92 93 /* @brief Connect to HID Services of remote device. 94 * 95 * @param con_handle 96 * @param packet_handler 97 * @param hids_cid 98 * @return status ERROR_CODE_SUCCESS on success, otherwise ERROR_CODE_COMMAND_DISALLOWED if there is already a client associated with con_handle, or BTSTACK_MEMORY_ALLOC_FAILED 99 */ 100 uint8_t hids_client_connect(hci_con_handle_t con_handle, btstack_packet_handler_t packet_handler, uint16_t * hids_cid); 101 102 /** 103 * @brief Disconnect from Battery Service. 104 * @param hids_cid 105 * @return status 106 */ 107 uint8_t hids_client_disconnect(uint16_t hids_cid); 108 109 /** 110 * @brief De-initialize Battery Service. 111 */ 112 void hids_client_deinit(void); 113 114 /* API_END */ 115 116 #if defined __cplusplus 117 } 118 #endif 119 120 #endif 121