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 IMMEDIATE_ALERT_SERVICE_CLIENT_H 44 #define IMMEDIATE_ALERT_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 #include "ble/gatt-service/immediate_alert_service_util.h" 53 54 #if defined __cplusplus 55 extern "C" { 56 #endif 57 58 /** 59 * @text The Immediate Alert Service Client 60 */ 61 typedef enum { 62 IMMEDIATE_ALERT_SERVICE_CLIENT_STATE_IDLE = 0, 63 IMMEDIATE_ALERT_SERVICE_CLIENT_STATE_W4_CONNECTION, 64 IMMEDIATE_ALERT_SERVICE_CLIENT_STATE_READY, 65 IMMEDIATE_ALERT_SERVICE_CLIENT_STATE_W2_WRITE_WITHOUT_RESPONSE_CHARACTERISTIC_VALUE 66 } immediate_alert_service_client_state_t; 67 68 typedef struct { 69 btstack_linked_item_t item; 70 71 gatt_service_client_connection_t basic_connection; 72 btstack_packet_handler_t packet_handler; 73 74 gatt_service_client_characteristic_t characteristics_storage[IMMEDIATE_ALERT_SERVICE_CLIENT_NUM_CHARACTERISTICS]; 75 76 immediate_alert_service_client_state_t state; 77 78 // Used for read characteristic queries 79 uint8_t characteristic_index; 80 // Used to store parameters for write characteristic 81 82 uint8_t write_buffer[1]; 83 } ias_client_connection_t; 84 85 /* API_START */ 86 87 88 /** 89 * @brief Initialize Immediate Alert Service. 90 */ 91 void immediate_alert_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 - disabled 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 == IMMEDIATE_ALERT_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 immediate_alert_service_client_connect( 110 hci_con_handle_t con_handle, 111 btstack_packet_handler_t packet_handler, 112 ias_client_connection_t * iac_connection, 113 uint16_t * ias_cid 114 ); 115 116 uint8_t immediate_alert_service_client_write_alert_level(uint16_t ias_cid, ias_alert_level_t alert_level); 117 118 119 /** 120 * @brief Disconnect. 121 * @param ias_cid 122 * @return status 123 */ 124 uint8_t immediate_alert_service_client_disconnect(uint16_t ias_cid); 125 126 /** 127 * @brief De-initialize Immediate Alert Service. 128 */ 129 void immediate_alert_service_client_deinit(void); 130 131 /* API_END */ 132 133 #if defined __cplusplus 134 } 135 #endif 136 137 #endif 138