1 /* 2 * Copyright (C) 2024 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 BLUEKITCHEN 24 * GMBH 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 /** 39 * @title Immediate Alert Service Client 40 * 41 */ 42 43 #ifndef TX_POWER_SERVICE_CLIENT_H 44 #define TX_POWER_SERVICE_CLIENT_H 45 46 #include <stdint.h> 47 #include "btstack_defines.h" 48 #include "bluetooth.h" 49 #include "btstack_linked_list.h" 50 #include "ble/gatt_client.h" 51 #include "ble/gatt_service_client.h" 52 53 #if defined __cplusplus 54 extern "C" { 55 #endif 56 57 // number of characteristics in Immediate Alert Service 58 #define TX_POWER_SERVICE_CLIENT_NUM_CHARACTERISTICS 1 59 60 /** 61 * @text The Immediate Alert Service Client 62 */ 63 typedef enum { 64 TX_POWER_SERVICE_CLIENT_STATE_IDLE = 0, 65 TX_POWER_SERVICE_CLIENT_STATE_W4_CONNECTION, 66 TX_POWER_SERVICE_CLIENT_STATE_READY, 67 TX_POWER_SERVICE_CLIENT_STATE_W2_READ_CHARACTERISTIC_VALUE, 68 TX_POWER_SERVICE_CLIENT_STATE_W4_READ_CHARACTERISTIC_VALUE_RESULT 69 } tx_power_service_client_state_t; 70 71 typedef struct { 72 btstack_linked_item_t item; 73 74 gatt_service_client_connection_t basic_connection; 75 btstack_packet_handler_t packet_handler; 76 77 tx_power_service_client_state_t state; 78 79 // Used for read characteristic queries 80 uint8_t characteristic_index; 81 // Used to store parameters for write characteristic 82 char write_buffer[11]; 83 } txps_client_connection_t; 84 85 /* API_START */ 86 87 88 /** 89 * @brief Initialize Immediate Alert Service. 90 */ 91 void tx_power_service_client_init(void); 92 93 /** 94 * @brief Connect to a Immediate Alert Service instance of remote device. The client will automatically register for notifications. 95 * The mute state is received via GATTSERVICE_SUBEVENT_LLS_CLIENT_MUTE event. 96 * The mute state can be 0 - off, 1 - on, 2 - disabeled and it is valid if the ATT status is equal to ATT_ERROR_SUCCESS, 97 * see ATT errors (see bluetooth.h) for other values. 98 * 99 * Event GATTSERVICE_SUBEVENT_LLS_CLIENT_CONNECTED is emitted with status ERROR_CODE_SUCCESS on success, otherwise 100 * GATT_CLIENT_IN_WRONG_STATE, ERROR_CODE_UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE if no audio input control service is found, or ATT errors (see bluetooth.h). 101 * 102 * @param con_handle 103 * @param packet_handler 104 * @param iac_connection 105 * @param iac_characteristics_storage storage for characteristics 106 * @param iac_characteristics_num == TX_POWER_SERVICE_CLIENT_NUM_CHARACTERISTICS 107 * @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 108 */ 109 uint8_t tx_power_service_client_connect( 110 hci_con_handle_t con_handle, 111 btstack_packet_handler_t packet_handler, 112 txps_client_connection_t * iac_connection, 113 gatt_service_client_characteristic_t * iac_characteristics_storage, uint8_t iac_characteristics_num, 114 uint16_t * txps_cid 115 ); 116 117 uint8_t tx_power_service_client_read_tx_power_level(uint16_t txps_cid); 118 119 /** 120 * @brief Disconnect. 121 * @param txps_cid 122 * @return status 123 */ 124 uint8_t tx_power_service_client_disconnect(uint16_t txps_cid); 125 126 /** 127 * @brief De-i nitialize Immediate Alert Service. 128 */ 129 void tx_power_service_client_deinit(void); 130 131 /* API_END */ 132 133 #if defined __cplusplus 134 } 135 #endif 136 137 #endif 138