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 struct bt_br_discovery_priv { 46 /** Clock offset */ 47 uint16_t clock_offset; 48 /** Page scan repetition mode */ 49 uint8_t pscan_rep_mode; 50 /** Resolving remote name*/ 51 bool resolving; 52 }; 53 54 /** @brief BR/EDR discovery result structure */ 55 struct bt_br_discovery_result { 56 /** Private data */ 57 struct bt_br_discovery_priv _priv; 58 59 /** Remote device address */ 60 bt_addr_t addr; 61 62 /** RSSI from inquiry */ 63 int8_t rssi; 64 65 /** Class of Device */ 66 uint8_t cod[3]; 67 68 /** Extended Inquiry Response */ 69 uint8_t eir[240]; 70 }; 71 72 /** BR/EDR discovery parameters */ 73 struct bt_br_discovery_param { 74 /** Maximum length of the discovery in units of 1.28 seconds. 75 * Valid range is 0x01 - 0x30. 76 */ 77 uint8_t length; 78 79 /** True if limited discovery procedure is to be used. */ 80 bool limited; 81 }; 82 83 /** 84 * @brief Start BR/EDR discovery 85 * 86 * Start BR/EDR discovery (inquiry) and provide results through the specified 87 * callback. The discovery results will be notified through callbacks 88 * registered by @ref bt_br_discovery_cb_register. 89 * If more inquiry results were received during session than 90 * fits in provided result storage, only ones with highest RSSI will be 91 * reported. 92 * 93 * @param param Discovery parameters. 94 * @param results Storage for discovery results. 95 * @param count Number of results in storage. Valid range: 1-255. 96 * 97 * @return Zero on success or error code otherwise, positive in case 98 * of protocol error or negative (POSIX) in case of stack internal error 99 */ 100 int bt_br_discovery_start(const struct bt_br_discovery_param *param, 101 struct bt_br_discovery_result *results, size_t count); 102 103 /** 104 * @brief Stop BR/EDR discovery. 105 * 106 * Stops ongoing BR/EDR discovery. If discovery was stopped by this call 107 * results won't be reported 108 * 109 * @return Zero on success or error code otherwise, positive in case of 110 * protocol error or negative (POSIX) in case of stack internal error. 111 */ 112 int bt_br_discovery_stop(void); 113 114 struct bt_br_discovery_cb { 115 116 /** 117 * @brief An inquiry response received callback. 118 * 119 * @param result Storage used for discovery results 120 */ 121 void (*recv)(const struct bt_br_discovery_result *result); 122 123 /** @brief The inquiry has stopped after discovery timeout. 124 * 125 * @param results Storage used for discovery results 126 * @param count Number of valid discovery results. 127 */ 128 void (*timeout)(const struct bt_br_discovery_result *results, 129 size_t count); 130 131 sys_snode_t node; 132 }; 133 134 /** 135 * @brief Register discovery packet callbacks. 136 * 137 * Adds the callback structure to the list of callback structures that monitors 138 * inquiry activity. 139 * 140 * This callback will be called for all inquiry activity, regardless of what 141 * API was used to start the discovery. 142 * 143 * @param cb Callback struct. Must point to memory that remains valid. 144 */ 145 void bt_br_discovery_cb_register(struct bt_br_discovery_cb *cb); 146 147 /** 148 * @brief Unregister discovery packet callbacks. 149 * 150 * Remove the callback structure from the list of discovery callbacks. 151 * 152 * @param cb Callback struct. Must point to memory that remains valid. 153 */ 154 void bt_br_discovery_cb_unregister(struct bt_br_discovery_cb *cb); 155 156 struct bt_br_oob { 157 /** BR/EDR address. */ 158 bt_addr_t addr; 159 }; 160 161 /** 162 * @brief Get BR/EDR local Out Of Band information 163 * 164 * This function allows to get local controller information that are useful 165 * for Out Of Band pairing or connection creation process. 166 * 167 * @param oob Out Of Band information 168 */ 169 int bt_br_oob_get_local(struct bt_br_oob *oob); 170 171 /** 172 * @brief Enable/disable set controller in discoverable state. 173 * 174 * Allows make local controller to listen on INQUIRY SCAN channel and responds 175 * to devices making general inquiry. To enable this state it's mandatory 176 * to first be in connectable state. 177 * 178 * @param enable Value allowing/disallowing controller to become discoverable. 179 * 180 * @return Negative if fail set to requested state or requested state has been 181 * already set. Zero if done successfully. 182 */ 183 int bt_br_set_discoverable(bool enable); 184 185 /** 186 * @brief Enable/disable set controller in connectable state. 187 * 188 * Allows make local controller to be connectable. It means the controller 189 * start listen to devices requests on PAGE SCAN channel. If disabled also 190 * resets discoverability if was set. 191 * 192 * @param enable Value allowing/disallowing controller to be connectable. 193 * 194 * @return Negative if fail set to requested state or requested state has been 195 * already set. Zero if done successfully. 196 */ 197 int bt_br_set_connectable(bool enable); 198 199 /** 200 * @} 201 */ 202 203 #ifdef __cplusplus 204 } 205 #endif 206 /** 207 * @} 208 */ 209 210 #endif /* ZEPHYR_INCLUDE_BLUETOOTH_CLASSIC_H_ */ 211