1 /* 2 * Copyright (C) 2022 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 Broadcast Audio Scan Service Server (BASS) 40 * 41 * @text The Broadcast Audio Scan Service is used by servers to expose their status with respect 42 * to synchronization to broadcast Audio Streams and associated data, including Broadcast_Codes 43 * used to decrypt encrypted broadcast Audio Streams. Clients can use the attributes exposed by 44 * servers to observe and/or request changes in server behavior. 45 * 46 * To use with your application, add `#import <broadcast_audio_scan_service.gatt>` to your .gatt file. 47 */ 48 49 #ifndef BROADCAST_AUDIO_SCAN_SERVICE_SERVER_H 50 #define BROADCAST_AUDIO_SCAN_SERVICE_SERVER_H 51 52 #include <stdint.h> 53 54 #include "btstack_defines.h" 55 #include "le-audio/le_audio.h" 56 57 #include "broadcast_audio_scan_service_util.h" 58 59 #if defined __cplusplus 60 extern "C" { 61 #endif 62 63 /* API_START */ 64 // memory for list of these structs is allocated by the application 65 typedef struct { 66 // assigned by client via control point 67 bass_source_data_t data; 68 69 uint8_t update_counter; 70 uint8_t source_id; 71 bool in_use; 72 73 le_audio_big_encryption_t big_encryption; 74 uint8_t bad_code[16]; 75 76 uint16_t bass_receive_state_handle; 77 uint16_t bass_receive_state_client_configuration_handle; 78 uint16_t bass_receive_state_client_configuration; 79 } bass_server_source_t; 80 81 typedef struct { 82 hci_con_handle_t con_handle; 83 uint16_t sources_to_notify; 84 85 // used for caching long write 86 uint8_t long_write_buffer[512]; 87 uint16_t long_write_value_size; 88 uint16_t long_write_attribute_handle; 89 } bass_server_connection_t; 90 91 /** 92 * @brief Init Broadcast Audio Scan Service Server with ATT DB 93 * @param sources_num 94 * @param sources 95 * @param clients_num 96 * @param clients 97 */ 98 void broadcast_audio_scan_service_server_init(uint8_t const sources_num, bass_server_source_t * sources, uint8_t const clients_num, bass_server_connection_t * clients); 99 100 /** 101 * @brief Register packet handler to receive events: 102 * - GATTSERVICE_SUBEVENT_BASS_SERVER_SCAN_STOPPED 103 * - GATTSERVICE_SUBEVENT_BASS_SERVER_SCAN_STARTED 104 * - GATTSERVICE_SUBEVENT_BASS_SERVER_BROADCAST_CODE 105 * - GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_ADDED 106 * - GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_MODIFIED 107 * - GATTSERVICE_SUBEVENT_BASS_SERVER_SOURCE_DELETED 108 * @param packet_handler 109 */ 110 void broadcast_audio_scan_service_server_register_packet_handler(btstack_packet_handler_t packet_handler); 111 112 /** 113 * @brief Set PA state of source. 114 * @param source_index 115 * @param sync_state 116 */ 117 void broadcast_audio_scan_service_server_set_pa_sync_state(uint8_t source_index, le_audio_pa_sync_state_t sync_state); 118 119 /** 120 * @brief Add source. 121 * @param source_data 122 * @param source_index 123 */ 124 void broadcast_audio_scan_service_server_add_source(const bass_source_data_t *source_data, uint8_t * source_index); 125 126 /** 127 * @brief Deinit Broadcast Audio Scan Service Server 128 */ 129 void broadcast_audio_scan_service_server_deinit(void); 130 131 /* API_END */ 132 133 #if defined __cplusplus 134 } 135 #endif 136 137 #endif 138 139