xref: /btstack/src/le-audio/gatt-service/broadcast_audio_scan_service_server.h (revision 3faa160f75c1f2da2f28f5c07981475e5ed0ba4e)
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_remote_client_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_remote_client_t * clients);
99 
100 /**
101  * @brief Register callback.
102  * @param callback
103  */
104 void broadcast_audio_scan_service_server_register_packet_handler(btstack_packet_handler_t callback);
105 
106 /**
107  * @brief Set PA state of source.
108  * @param source_index
109  * @param sync_state
110  */
111 void broadcast_audio_scan_service_server_set_pa_sync_state(uint8_t source_index, le_audio_pa_sync_state_t sync_state);
112 
113 /**
114  * @brief Register callback.
115  * @param source_data
116  * @param source_index
117  */
118 void broadcast_audio_scan_service_server_add_source(bass_source_data_t source_data, uint8_t * source_index);
119 
120 /**
121  * @brief Deinit Broadcast Audio Scan Service Server
122  */
123 void broadcast_audio_scan_service_server_deinit(void);
124 
125 /* API_END */
126 
127 #if defined __cplusplus
128 }
129 #endif
130 
131 #endif
132 
133