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