1*a9cf7f99SMatthias Ringwald /* 2*a9cf7f99SMatthias Ringwald * Copyright (C) 2024 BlueKitchen GmbH 3*a9cf7f99SMatthias Ringwald * 4*a9cf7f99SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5*a9cf7f99SMatthias Ringwald * modification, are permitted provided that the following conditions 6*a9cf7f99SMatthias Ringwald * are met: 7*a9cf7f99SMatthias Ringwald * 8*a9cf7f99SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9*a9cf7f99SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10*a9cf7f99SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11*a9cf7f99SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12*a9cf7f99SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13*a9cf7f99SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14*a9cf7f99SMatthias Ringwald * contributors may be used to endorse or promote products derived 15*a9cf7f99SMatthias Ringwald * from this software without specific prior written permission. 16*a9cf7f99SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17*a9cf7f99SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18*a9cf7f99SMatthias Ringwald * monetary gain. 19*a9cf7f99SMatthias Ringwald * 20*a9cf7f99SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21*a9cf7f99SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*a9cf7f99SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*a9cf7f99SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24*a9cf7f99SMatthias Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25*a9cf7f99SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26*a9cf7f99SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27*a9cf7f99SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28*a9cf7f99SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29*a9cf7f99SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30*a9cf7f99SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*a9cf7f99SMatthias Ringwald * SUCH DAMAGE. 32*a9cf7f99SMatthias Ringwald * 33*a9cf7f99SMatthias Ringwald * Please inquire about commercial licensing options at 34*a9cf7f99SMatthias Ringwald * [email protected] 35*a9cf7f99SMatthias Ringwald * 36*a9cf7f99SMatthias Ringwald */ 37*a9cf7f99SMatthias Ringwald 38*a9cf7f99SMatthias Ringwald /** 39*a9cf7f99SMatthias Ringwald * @title Immediate Alert Service Client 40*a9cf7f99SMatthias Ringwald * 41*a9cf7f99SMatthias Ringwald */ 42*a9cf7f99SMatthias Ringwald 43*a9cf7f99SMatthias Ringwald #ifndef TX_POWER_SERVICE_CLIENT_H 44*a9cf7f99SMatthias Ringwald #define TX_POWER_SERVICE_CLIENT_H 45*a9cf7f99SMatthias Ringwald 46*a9cf7f99SMatthias Ringwald #include <stdint.h> 47*a9cf7f99SMatthias Ringwald #include "btstack_defines.h" 48*a9cf7f99SMatthias Ringwald #include "bluetooth.h" 49*a9cf7f99SMatthias Ringwald #include "btstack_linked_list.h" 50*a9cf7f99SMatthias Ringwald #include "ble/gatt_client.h" 51*a9cf7f99SMatthias Ringwald #include "ble/gatt_service_client.h" 52*a9cf7f99SMatthias Ringwald 53*a9cf7f99SMatthias Ringwald #if defined __cplusplus 54*a9cf7f99SMatthias Ringwald extern "C" { 55*a9cf7f99SMatthias Ringwald #endif 56*a9cf7f99SMatthias Ringwald 57*a9cf7f99SMatthias Ringwald // number of characteristics in Immediate Alert Service 58*a9cf7f99SMatthias Ringwald #define TX_POWER_SERVICE_CLIENT_NUM_CHARACTERISTICS 1 59*a9cf7f99SMatthias Ringwald 60*a9cf7f99SMatthias Ringwald /** 61*a9cf7f99SMatthias Ringwald * @text The Immediate Alert Service Client 62*a9cf7f99SMatthias Ringwald */ 63*a9cf7f99SMatthias Ringwald typedef enum { 64*a9cf7f99SMatthias Ringwald TX_POWER_SERVICE_CLIENT_STATE_IDLE = 0, 65*a9cf7f99SMatthias Ringwald TX_POWER_SERVICE_CLIENT_STATE_W4_CONNECTION, 66*a9cf7f99SMatthias Ringwald TX_POWER_SERVICE_CLIENT_STATE_READY, 67*a9cf7f99SMatthias Ringwald TX_POWER_SERVICE_CLIENT_STATE_W2_READ_CHARACTERISTIC_VALUE, 68*a9cf7f99SMatthias Ringwald TX_POWER_SERVICE_CLIENT_STATE_W4_READ_CHARACTERISTIC_VALUE_RESULT 69*a9cf7f99SMatthias Ringwald } tx_power_service_client_state_t; 70*a9cf7f99SMatthias Ringwald 71*a9cf7f99SMatthias Ringwald typedef struct { 72*a9cf7f99SMatthias Ringwald btstack_linked_item_t item; 73*a9cf7f99SMatthias Ringwald 74*a9cf7f99SMatthias Ringwald gatt_service_client_connection_t basic_connection; 75*a9cf7f99SMatthias Ringwald btstack_packet_handler_t packet_handler; 76*a9cf7f99SMatthias Ringwald 77*a9cf7f99SMatthias Ringwald tx_power_service_client_state_t state; 78*a9cf7f99SMatthias Ringwald 79*a9cf7f99SMatthias Ringwald // Used for read characteristic queries 80*a9cf7f99SMatthias Ringwald uint8_t characteristic_index; 81*a9cf7f99SMatthias Ringwald // Used to store parameters for write characteristic 82*a9cf7f99SMatthias Ringwald char write_buffer[11]; 83*a9cf7f99SMatthias Ringwald } txps_client_connection_t; 84*a9cf7f99SMatthias Ringwald 85*a9cf7f99SMatthias Ringwald /* API_START */ 86*a9cf7f99SMatthias Ringwald 87*a9cf7f99SMatthias Ringwald 88*a9cf7f99SMatthias Ringwald /** 89*a9cf7f99SMatthias Ringwald * @brief Initialize Immediate Alert Service. 90*a9cf7f99SMatthias Ringwald */ 91*a9cf7f99SMatthias Ringwald void tx_power_service_client_init(void); 92*a9cf7f99SMatthias Ringwald 93*a9cf7f99SMatthias Ringwald /** 94*a9cf7f99SMatthias Ringwald * @brief Connect to a Immediate Alert Service instance of remote device. The client will automatically register for notifications. 95*a9cf7f99SMatthias Ringwald * The mute state is received via GATTSERVICE_SUBEVENT_LLS_CLIENT_MUTE event. 96*a9cf7f99SMatthias Ringwald * 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*a9cf7f99SMatthias Ringwald * see ATT errors (see bluetooth.h) for other values. 98*a9cf7f99SMatthias Ringwald * 99*a9cf7f99SMatthias Ringwald * Event GATTSERVICE_SUBEVENT_LLS_CLIENT_CONNECTED is emitted with status ERROR_CODE_SUCCESS on success, otherwise 100*a9cf7f99SMatthias Ringwald * 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*a9cf7f99SMatthias Ringwald * 102*a9cf7f99SMatthias Ringwald * @param con_handle 103*a9cf7f99SMatthias Ringwald * @param packet_handler 104*a9cf7f99SMatthias Ringwald * @param iac_connection 105*a9cf7f99SMatthias Ringwald * @param iac_characteristics_storage storage for characteristics 106*a9cf7f99SMatthias Ringwald * @param iac_characteristics_num == TX_POWER_SERVICE_CLIENT_NUM_CHARACTERISTICS 107*a9cf7f99SMatthias Ringwald * @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*a9cf7f99SMatthias Ringwald */ 109*a9cf7f99SMatthias Ringwald uint8_t tx_power_service_client_connect( 110*a9cf7f99SMatthias Ringwald hci_con_handle_t con_handle, 111*a9cf7f99SMatthias Ringwald btstack_packet_handler_t packet_handler, 112*a9cf7f99SMatthias Ringwald txps_client_connection_t * iac_connection, 113*a9cf7f99SMatthias Ringwald gatt_service_client_characteristic_t * iac_characteristics_storage, uint8_t iac_characteristics_num, 114*a9cf7f99SMatthias Ringwald uint16_t * txps_cid 115*a9cf7f99SMatthias Ringwald ); 116*a9cf7f99SMatthias Ringwald 117*a9cf7f99SMatthias Ringwald uint8_t tx_power_service_client_read_tx_power_level(uint16_t txps_cid); 118*a9cf7f99SMatthias Ringwald 119*a9cf7f99SMatthias Ringwald /** 120*a9cf7f99SMatthias Ringwald * @brief Disconnect. 121*a9cf7f99SMatthias Ringwald * @param txps_cid 122*a9cf7f99SMatthias Ringwald * @return status 123*a9cf7f99SMatthias Ringwald */ 124*a9cf7f99SMatthias Ringwald uint8_t tx_power_service_client_disconnect(uint16_t txps_cid); 125*a9cf7f99SMatthias Ringwald 126*a9cf7f99SMatthias Ringwald /** 127*a9cf7f99SMatthias Ringwald * @brief De-i nitialize Immediate Alert Service. 128*a9cf7f99SMatthias Ringwald */ 129*a9cf7f99SMatthias Ringwald void tx_power_service_client_deinit(void); 130*a9cf7f99SMatthias Ringwald 131*a9cf7f99SMatthias Ringwald /* API_END */ 132*a9cf7f99SMatthias Ringwald 133*a9cf7f99SMatthias Ringwald #if defined __cplusplus 134*a9cf7f99SMatthias Ringwald } 135*a9cf7f99SMatthias Ringwald #endif 136*a9cf7f99SMatthias Ringwald 137*a9cf7f99SMatthias Ringwald #endif 138