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