Line data Source code
1 1 : /** @file
2 : * @brief Bluetooth subsystem classic core APIs.
3 : */
4 :
5 : /*
6 : * Copyright (c) 2015-2016 Intel Corporation
7 : * Copyright 2024 NXP
8 : *
9 : * SPDX-License-Identifier: Apache-2.0
10 : */
11 : #ifndef ZEPHYR_INCLUDE_BLUETOOTH_CLASSIC_H_
12 : #define ZEPHYR_INCLUDE_BLUETOOTH_CLASSIC_H_
13 :
14 : /**
15 : * @brief Bluetooth APIs
16 : * @defgroup bluetooth Bluetooth APIs
17 : * @ingroup connectivity
18 : * @{
19 : */
20 :
21 : #include <stdbool.h>
22 : #include <string.h>
23 :
24 : #include <zephyr/sys/util.h>
25 : #include <zephyr/net_buf.h>
26 : #include <zephyr/bluetooth/addr.h>
27 :
28 : #ifdef __cplusplus
29 : extern "C" {
30 : #endif
31 :
32 : /**
33 : * @brief Generic Access Profile (GAP)
34 : * @defgroup bt_gap Generic Access Profile (GAP)
35 : * @since 1.0
36 : * @version 1.0.0
37 : * @ingroup bluetooth
38 : * @{
39 : */
40 :
41 : /**
42 : * @private
43 : * @brief BR/EDR discovery private structure
44 : */
45 1 : struct bt_br_discovery_priv {
46 : /** Clock offset */
47 1 : uint16_t clock_offset;
48 : /** Page scan repetition mode */
49 1 : uint8_t pscan_rep_mode;
50 : /** Resolving remote name*/
51 1 : uint8_t resolve_state;
52 : };
53 :
54 : /** Maximum size of Extended Inquiry Response */
55 1 : #define BT_BR_EIR_SIZE_MAX 240
56 :
57 : /** @brief BR/EDR discovery result structure */
58 1 : struct bt_br_discovery_result {
59 : /** Private data */
60 : struct bt_br_discovery_priv _priv;
61 :
62 : /** Remote device address */
63 1 : bt_addr_t addr;
64 :
65 : /** RSSI from inquiry */
66 1 : int8_t rssi;
67 :
68 : /** Class of Device */
69 1 : uint8_t cod[3];
70 :
71 : /** Extended Inquiry Response */
72 1 : uint8_t eir[BT_BR_EIR_SIZE_MAX];
73 : };
74 :
75 : /** BR/EDR discovery parameters */
76 1 : struct bt_br_discovery_param {
77 : /** Maximum length of the discovery in units of 1.28 seconds.
78 : * Valid range is 0x01 - 0x30.
79 : */
80 1 : uint8_t length;
81 :
82 : /** True if limited discovery procedure is to be used. */
83 1 : bool limited;
84 : };
85 :
86 : /**
87 : * @brief Start BR/EDR discovery
88 : *
89 : * Start BR/EDR discovery (inquiry) and provide results through the specified
90 : * callback. The discovery results will be notified through callbacks
91 : * registered by @ref bt_br_discovery_cb_register.
92 : * If more inquiry results were received during session than
93 : * fits in provided result storage, only ones with highest RSSI will be
94 : * reported.
95 : *
96 : * @param param Discovery parameters.
97 : * @param results Storage for discovery results.
98 : * @param count Number of results in storage. Valid range: 1-255.
99 : *
100 : * @return Zero on success or error code otherwise, positive in case
101 : * of protocol error or negative (POSIX) in case of stack internal error
102 : */
103 1 : int bt_br_discovery_start(const struct bt_br_discovery_param *param,
104 : struct bt_br_discovery_result *results, size_t count);
105 :
106 : /**
107 : * @brief Stop BR/EDR discovery.
108 : *
109 : * Stops ongoing BR/EDR discovery. If discovery was stopped by this call
110 : * results won't be reported
111 : *
112 : * @return Zero on success or error code otherwise, positive in case of
113 : * protocol error or negative (POSIX) in case of stack internal error.
114 : */
115 1 : int bt_br_discovery_stop(void);
116 :
117 0 : struct bt_br_discovery_cb {
118 :
119 : /**
120 : * @brief An inquiry response received callback.
121 : *
122 : * @param result Storage used for discovery results
123 : */
124 1 : void (*recv)(const struct bt_br_discovery_result *result);
125 :
126 : /** @brief The inquiry has stopped after discovery timeout.
127 : *
128 : * @param results Storage used for discovery results
129 : * @param count Number of valid discovery results.
130 : */
131 1 : void (*timeout)(const struct bt_br_discovery_result *results,
132 : size_t count);
133 :
134 0 : sys_snode_t node;
135 : };
136 :
137 : /**
138 : * @brief Register discovery packet callbacks.
139 : *
140 : * Adds the callback structure to the list of callback structures that monitors
141 : * inquiry activity.
142 : *
143 : * This callback will be called for all inquiry activity, regardless of what
144 : * API was used to start the discovery.
145 : *
146 : * @param cb Callback struct. Must point to memory that remains valid.
147 : */
148 1 : void bt_br_discovery_cb_register(struct bt_br_discovery_cb *cb);
149 :
150 : /**
151 : * @brief Unregister discovery packet callbacks.
152 : *
153 : * Remove the callback structure from the list of discovery callbacks.
154 : *
155 : * @param cb Callback struct. Must point to memory that remains valid.
156 : */
157 1 : void bt_br_discovery_cb_unregister(struct bt_br_discovery_cb *cb);
158 :
159 0 : struct bt_br_oob {
160 : /** BR/EDR address. */
161 1 : bt_addr_t addr;
162 : };
163 :
164 : /**
165 : * @brief Get BR/EDR local Out Of Band information
166 : *
167 : * This function allows to get local controller information that are useful
168 : * for Out Of Band pairing or connection creation process.
169 : *
170 : * @param oob Out Of Band information
171 : */
172 1 : int bt_br_oob_get_local(struct bt_br_oob *oob);
173 :
174 : /**
175 : * @brief Enable/disable set controller in discoverable state.
176 : *
177 : * Allows make local controller to listen on INQUIRY SCAN channel and responds
178 : * to devices making general inquiry. To enable this state it's mandatory
179 : * to first be in connectable state.
180 : *
181 : * If the device enters limited discoverable mode, the controller will leave from discoverable
182 : * mode after the duration of @kconfig{BT_LIMITED_DISCOVERABLE_DURATION} seconds in the limited
183 : * discoverable mode.
184 : *
185 : * @param enable Value allowing/disallowing controller to become discoverable.
186 : * @param limited Value allowing/disallowing controller to enter limited discoverable mode.
187 : *
188 : * @return Negative if fail set to requested state or requested state has been
189 : * already set. Zero if done successfully.
190 : */
191 1 : int bt_br_set_discoverable(bool enable, bool limited);
192 :
193 : /**
194 : * @brief Enable/disable set controller in connectable state.
195 : *
196 : * Allows make local controller to be connectable. It means the controller
197 : * start listen to devices requests on PAGE SCAN channel. If disabled also
198 : * resets discoverability if was set.
199 : *
200 : * @param enable Value allowing/disallowing controller to be connectable.
201 : *
202 : * @return Negative if fail set to requested state or requested state has been
203 : * already set. Zero if done successfully.
204 : */
205 1 : int bt_br_set_connectable(bool enable);
206 :
207 : /** @brief Check if a Bluetooth classic device address is bonded.
208 : *
209 : * @param addr Bluetooth classic device address.
210 : *
211 : * @return true if @p addr is bonded
212 : */
213 1 : bool bt_br_bond_exists(const bt_addr_t *addr);
214 :
215 : /**
216 : * @brief Clear classic pairing information .
217 : *
218 : * @param addr Remote address, NULL or BT_ADDR_ANY to clear all remote devices.
219 : *
220 : * @return 0 on success or negative error value on failure.
221 : */
222 1 : int bt_br_unpair(const bt_addr_t *addr);
223 :
224 : /** Information about a bond with a remote device. */
225 1 : struct bt_br_bond_info {
226 : /** Address of the remote device. */
227 1 : bt_addr_t addr;
228 : };
229 :
230 : /**
231 : * @brief Iterate through all existing bonds of Classic.
232 : *
233 : * @param func Function to call for each bond.
234 : * @param user_data Data to pass to the callback function.
235 : */
236 1 : void bt_br_foreach_bond(void (*func)(const struct bt_br_bond_info *info, void *user_data),
237 : void *user_data);
238 :
239 : /**
240 : * @}
241 : */
242 :
243 : #ifdef __cplusplus
244 : }
245 : #endif
246 : /**
247 : * @}
248 : */
249 :
250 : #endif /* ZEPHYR_INCLUDE_BLUETOOTH_CLASSIC_H_ */
|