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 #ifndef BROADCAST_AUDIO_SCAN_SERVICE_UTIL_H 40 #define BROADCAST_AUDIO_SCAN_SERVICE_UTIL_H 41 42 #include <stdint.h> 43 44 #include "btstack_bool.h" 45 #include "le-audio/le_audio.h" 46 47 #if defined __cplusplus 48 extern "C" { 49 #endif 50 51 #define BASS_ERROR_CODE_OPCODE_NOT_SUPPORTED 0x80 52 #define BASS_ERROR_CODE_INVALID_SOURCE_ID 0x81 53 #define BASS_SUBGROUPS_MAX_NUM 10 54 55 #define BASS_MAX_NOTIFY_BUFFER_SIZE 200 56 #define BASS_INVALID_SOURCE_INDEX 0xFF 57 58 /* API_START */ 59 60 typedef enum { 61 BASS_OPCODE_REMOTE_SCAN_STOPPED = 0x00, 62 BASS_OPCODE_REMOTE_SCAN_STARTED, 63 BASS_OPCODE_ADD_SOURCE, 64 BASS_OPCODE_MODIFY_SOURCE, 65 BASS_OPCODE_SET_BROADCAST_CODE, 66 BASS_OPCODE_REMOVE_SOURCE, 67 BASS_OPCODE_RFU 68 } bass_opcode_t; 69 70 typedef enum { 71 BASS_ROLE_CLIENT = 0, 72 BASS_ROLE_SERVER 73 } bass_role_t; 74 75 typedef struct { 76 // BIS_Sync parameter 77 // 4-octet bitfield. Shall not exist if Num_Subgroups = 0 78 // Bit 0-30 = BIS_index[1-31] 0x00000000: 79 // - 0b0 = Do not synchronize to BIS_index[x] 0xxxxxxxxx: 80 // - 0b1 = Synchronize to BIS_index[x] 81 // 0xFFFFFFFF: No preference 82 // written by client into control point 83 uint32_t bis_sync; 84 85 // 4-octet bitfield. Shall not exist if num_subgroups = 0 86 // Bit 0-30 = BIS_index[1-31] 87 // 0x00000000: 0 = Not synchronized to BIS_index[x] 88 // 0xxxxxxxxx: 1 = Synchronized to BIS_index[x] 89 // 0xFFFFFFFF: Failed to sync to BIG 90 // state send to client by server 91 uint32_t bis_sync_state; 92 93 uint8_t metadata_length; 94 le_audio_metadata_t metadata; 95 } bass_subgroup_t; 96 97 typedef struct { 98 // assigned by client via control point 99 bd_addr_type_t address_type; 100 bd_addr_t address; 101 uint8_t adv_sid; 102 uint32_t broadcast_id; 103 le_audio_pa_sync_t pa_sync; // written by client into control point 104 le_audio_pa_sync_state_t pa_sync_state; // state send to client by server 105 uint16_t pa_interval; 106 107 uint8_t subgroups_num; 108 // Shall not exist if num_subgroups = 0 109 bass_subgroup_t subgroups[BASS_SUBGROUPS_MAX_NUM]; 110 } bass_source_data_t; 111 112 // offset gives position into fully serialized BASS record 113 uint16_t bass_util_source_data_header_virtual_memcpy(const bass_source_data_t * data, uint16_t *source_offset, uint16_t buffer_offset, uint8_t * buffer, uint16_t buffer_size); 114 115 uint16_t bass_util_source_data_subgroups_virtual_memcpy(const bass_source_data_t *data, bool use_state_fields, uint16_t *source_offset, 116 uint16_t buffer_offset, uint8_t *buffer, uint16_t buffer_size); 117 118 bool bass_util_pa_sync_state_and_subgroups_in_valid_range(const uint8_t *buffer, uint16_t buffer_size); 119 120 bool bass_util_source_buffer_in_valid_range(const uint8_t *buffer, uint16_t buffer_size); 121 122 void bass_util_source_data_parse(const uint8_t *buffer, uint16_t buffer_size, bass_source_data_t *source_data, 123 bool is_broadcast_receive_state); 124 125 void bass_util_pa_info_and_subgroups_parse(const uint8_t *buffer, uint16_t buffer_size, bass_source_data_t *source_data, 126 bool is_broadcast_receive_state); 127 128 /* API_END */ 129 130 #if defined __cplusplus 131 } 132 #endif 133 134 #endif 135 136