Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
298 changes: 298 additions & 0 deletions include/zephyr/bluetooth/classic/classic.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,304 @@ int bt_br_set_discoverable(bool enable, bool limited);
*/
int bt_br_set_connectable(bool enable);

/**
* @name Defined BR/EDR Page Scan timers
* @{
*/
#define BT_BR_PAGE_SCAN_INTERVAL_R0 0x0800 /* 0x0800, 1.280s, U:0.625 */
#define BT_BR_PAGE_SCAN_WINDOW_R0 0x0800 /* 0x0800, 1.280s, U:0.625 */

#define BT_BR_PAGE_SCAN_FAST_INTERVAL_R1 0x00a0 /* 0x00a0, 100.0ms, U:0.625 */
#define BT_BR_PAGE_SCAN_FAST_WINDOW_R1 0x0011 /* 0x0011, 10.625ms, U:0.625 */

#define BT_BR_PAGE_SCAN_MEDIUM_INTERVAL_R1 0x0800 /* 0x0800, 1.280s, U:0.625 */
#define BT_BR_PAGE_SCAN_MEDIUM_WINDOW_R1 0x0011 /* 0x0011, 10.625ms, U:0.625 */

#define BT_BR_PAGE_SCAN_SLOW_INTERVAL_R1 0x0800 /* 0x0800, 1.280s, U:0.625 */
#define BT_BR_PAGE_SCAN_SLOW_WINDOW_R1 0x0011 /* 0x0011, 10.625ms, U:0.625 */

#define BT_BR_PAGE_SCAN_FAST_INTERVAL_R2 0x1000 /* 0x1000, 2.560s, U:0.625 */
#define BT_BR_PAGE_SCAN_FAST_WINDOW_R2 0x0011 /* 0x0011, 10.625ms, U:0.625 */

#define BT_BR_PAGE_SCAN_SLOW_INTERVAL_R2 0x1000 /* 0x1000, 2.560s, U:0.625 */
#define BT_BR_PAGE_SCAN_SLOW_WINDOW_R2 0x0011 /* 0x0011, 10.625ms, U:0.625 */
/**
* @}
*/

/** Page scan type. */
enum bt_br_scan_type {
/** Standard scan (default) */
BT_BR_SCAN_TYPE_STANDARD = 0,

/** Interlaced scan (1.2 devices only) */
BT_BR_SCAN_TYPE_INTERLACED = 1,
};

struct bt_br_page_scan_param {
/** Page scan interval in 0.625 ms units
* Range: 0x0012 to 0x1000; only even values are valid.
*/
uint16_t interval;

/** Page scan window in 0.625 ms units
* Range: 0x0011 to 0x1000.
*/
uint16_t window;

/** Page scan type. */
enum bt_br_scan_type type;
};

/**
* @brief Initialize BR Scan parameters
*
* @param _interval Scan interval
* @param _window Scan window
* @param _type Scan type
*/

#define BT_BR_SCAN_INIT(_interval, _window, _type) \
{ \
.interval = (_interval), \
.window = (_window), \
.type = (_type) \
}

/**
* Helper to declare BR/EDR page scan parameters inline
*
* @param _interval page scan interval, N * 0.625 milliseconds
* @param _window page scan window, N * 0.625 milliseconds
* @param _type BT_BR_SCAN_TYPE_STANDARD or BT_BR_SCAN_TYPE_INTERLACED
*/

#define BT_BR_PAGE_SCAN_PARAM(_interval, _window, _type) \
((const struct bt_br_page_scan_param[]) { \
BT_BR_SCAN_INIT(_interval, _window, _type) \
})

/**
* @brief Default page scan parameters for R0
*
* Page scan interval and window are set to 1.280 seconds (0x0800 in 0.625 ms units).
* The scan type is set to standard.
*/
#define BT_BR_PAGE_SCAN_PARAM_R0 BT_BR_PAGE_SCAN_PARAM(BT_BR_PAGE_SCAN_INTERVAL_R0, \
BT_BR_PAGE_SCAN_WINDOW_R0, \
BT_BR_SCAN_TYPE_STANDARD)

/**
* @brief Fast page scan parameters for R1
*
* Page scan interval is set to 100 ms (0x00A0 in 0.625 ms units), and the
* page scan window is set to 10.240 seconds (0x27FF in 1 ms units).
* The scan type is set to interlaced.
*/
#define BT_BR_PAGE_SCAN_PARAM_FAST_R1 \
BT_BR_PAGE_SCAN_PARAM(BT_BR_PAGE_SCAN_FAST_INTERVAL_R1, \
BT_BR_PAGE_SCAN_FAST_WINDOW_R1, \
BT_BR_SCAN_TYPE_INTERLACED)

/**
* @brief Medium page scan parameters for R1
*
* Page scan interval and window are set to 1.280 seconds (0x0800 in 0.625 ms units).
* The scan type is set to standard.
*/
#define BT_BR_PAGE_SCAN_PARAM_MEDIUM_R1 \
BT_BR_PAGE_SCAN_PARAM( \
BT_BR_PAGE_SCAN_MEDIUM_INTERVAL_R1, \
BT_BR_PAGE_SCAN_MEDIUM_WINDOW_R1, \
BT_BR_SCAN_TYPE_INTERLACED)

/**
* @brief Slow page scan parameters for R1
*
* Page scan interval and window are set to 1.280 seconds (0x0800 in 0.625 ms units).
* The scan type is set to standard.
*/
#define BT_BR_PAGE_SCAN_PARAM_SLOW_R1 \
BT_BR_PAGE_SCAN_PARAM( \
BT_BR_PAGE_SCAN_SLOW_INTERVAL_R1, \
BT_BR_PAGE_SCAN_SLOW_WINDOW_R1, \
BT_BR_SCAN_TYPE_STANDARD)

/**
* @brief Fast page scan parameters for R2
*
* Page scan interval is set to 2.560 seconds (0x1000 in 0.625 ms units), and the
* page scan window is set to 10.240 seconds (0x27FF in 1 ms units).
* The scan type is set to standard.
*/
#define BT_BR_PAGE_SCAN_PARAM_FAST_R2 \
BT_BR_PAGE_SCAN_PARAM( \
BT_BR_PAGE_SCAN_FAST_INTERVAL_R2, \
BT_BR_PAGE_SCAN_FAST_WINDOW_R2, \
BT_BR_SCAN_TYPE_INTERLACED)

/**
* @brief Slow page scan parameters for R2
*
* Page scan interval and window are set to 2.560 seconds (0x1000 in 0.625 ms units).
* The scan type is set to standard.
*/
#define BT_BR_PAGE_SCAN_PARAM_SLOW_R2 \
BT_BR_PAGE_SCAN_PARAM( \
BT_BR_PAGE_SCAN_SLOW_INTERVAL_R2, \
BT_BR_PAGE_SCAN_SLOW_WINDOW_R2, \
BT_BR_SCAN_TYPE_STANDARD)

/**
* @brief Update BR/EDR page scan parameters.
*
* This function updates the page scan parameters of the local BR/EDR controller.
* Page scan parameters determine how the controller listens for incoming
* connection requests from remote devices.
*
* The function validates the provided parameters, including the interval,
* window, and scan type, and sends the appropriate HCI commands to update
* the controller's page scan activity and scan type.
*
* The user can set custom page scan parameters using the helper macro
* `BT_BR_PAGE_SCAN_PARAM(interval, window, type)` to define their own values.
* Alternatively, the user can use predefined standard parameters as defined
* in the Bluetooth specification:
* - `BT_BR_PAGE_SCAN_PARAM_R0`: Default page scan parameters.
* - `BT_BR_PAGE_SCAN_PARAM_FAST_R1`: Fast page scan parameters for R1.
* - `BT_BR_PAGE_SCAN_PARAM_MEDIUM_R1`: Medium page scan parameters for R1.
* - `BT_BR_PAGE_SCAN_PARAM_SLOW_R1`: Slow page scan parameters for R1.
* - `BT_BR_PAGE_SCAN_PARAM_FAST_R2`: Fast page scan parameters for R2.
* - `BT_BR_PAGE_SCAN_PARAM_SLOW_R2`: Slow page scan parameters for R2.
*
* These predefined parameters are designed to meet common use cases and
* ensure compliance with the Bluetooth specification.
*
* @param param Page scan parameters, including:
* - interval: Time between consecutive page scans (in 0.625 ms units).
* Must be in the range [0x0012, 0x1000].
* - window: Duration of a single page scan (in 0.625 ms units).
* Must be in the range [0x0011, 0x1000].
* - type: Page scan type (e.g., standard or interlaced).
*
* @return 0 on success.
* @return -EINVAL if the provided parameters are invalid.
* @return -EAGAIN if the device is not ready.
* @return -ENOBUFS if memory allocation for HCI commands fails.
* @return Other negative error codes for internal failures.
*/
int bt_br_page_scan_update_param(const struct bt_br_page_scan_param *param);

/**
* @brief BR/EDR inquiry scan parameters
* @note These parameters are used to configure the inquiry scan behavior of the
* local BR/EDR controller.
*/
struct bt_br_inquiry_scan_param {
/** Inquiry scan interval in 0.625 ms units
* Range: 0x0012 to 0x1000; only even values are valid.
*/
uint16_t interval;

/** Inquiry scan window in 0.625 ms units
* Range: 0x0011 to 0x1000.
*/
uint16_t window;

/** Inquiry scan type. */
enum bt_br_scan_type type;
};

/**
* @name Defined BR Page Scan timers
* @{
*/
#define BT_BR_INQUIRY_SCAN_INTERVAL_DEFAULT 0x1000 /* 0x1000, 2.560s, U:0.625 */
#define BT_BR_INQUIRY_SCAN_WINDOW_DEFAULT 0x0012 /* 0x0012, 11.25mss, U:0.625 */
/**
* @}
*/

/**
* Helper to declare BR/EDR inquiry scan parameters inline
*
* @param _interval Inquiry scan interval, N * 0.625 milliseconds
* @param _window Inquiry scan window, N * 0.625 milliseconds
* @param _type BT_BR_SCAN_TYPE_STANDARD or BT_BR_SCAN_TYPE_INTERLACED
*/
#define BT_BR_INQUIRY_SCAN_PARAM(_interval, _window, _type) \
((const struct bt_br_inquiry_scan_param[]) { \
BT_BR_SCAN_INIT(_interval, _window, _type) \
})

/**
* @brief Default inquiry scan parameters
*
* Inquiry scan interval is set to 2.560 seconds (0x1000 in 0.625 ms units), and the
* inquiry scan window is set to 11.25 milliseconds (0x0012 in 0.625 ms units).
* The scan type is set to standard.
*/
#define BT_BR_INQUIRY_SCAN_PARAM_DEFAULT \
BT_BR_INQUIRY_SCAN_PARAM( \
BT_BR_INQUIRY_SCAN_INTERVAL_DEFAULT, \
BT_BR_INQUIRY_SCAN_WINDOW_DEFAULT, \
BT_BR_SCAN_TYPE_STANDARD)

/**
* @brief Update BR/EDR inquiry scan parameters.
*
* This function updates the inquiry scan parameters of the local BR/EDR controller.
* Inquiry scan parameters determine how the controller handle inquiry requests.
*
* The function validates the provided parameters, including the interval,
* window, and scan type, and sends the appropriate HCI commands to update
* the controller's inquiry scan activity and scan type.
*
* The user can set custom inquiry scan parameters using the helper macro
* `BT_BR_INQUIRY_SCAN_PARAM(interval, window, type)` to define their own values.
* Alternatively, the user can use predefined standard parameters as defined
* in the Bluetooth specification:
* - `BT_BR_INQUIRY_SCAN_PARAM_DEFAULT`: Default inquiry scan parameters.
* These predefined parameters are designed to meet common use cases and
* ensure compliance with the Bluetooth specification.
*
* @param param Inquiry scan parameters, including:
* - interval: Time between consecutive inquiry scans (in 0.625 ms units).
* Must be in the range [0x0012, 0x1000].
* - window: Duration of a single inquiry scan (in 0.625 ms units).
* Must be in the range [0x0011, 0x1000].
* - type: Inquiry scan type (e.g., standard or interlaced).
*
* @return 0 on success.
* @return -EINVAL if the provided parameters are invalid.
* @return -EAGAIN if the device is not ready.
* @return -ENOBUFS if memory allocation for HCI commands fails.
* @return Other negative error codes for internal failures.
*/
int bt_br_inquiry_scan_update_param(const struct bt_br_inquiry_scan_param *param);

/**
* @brief Set the Class of Device configuration parameter of the local
* BR/EDR Controller.
*
* @param cod Class of Device value.
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_set_class_of_device(uint32_t cod);

/**
* @brief Get the Class of Device configuration parameter of the local
* BR/EDR Controller.
*
* @param cod Class of Device value.
*
* @return Negative if fail set to requested state or requested state has been
* already set. Zero if done successfully.
*/
int bt_br_get_class_of_device(uint32_t *cod);

/** @brief Check if a Bluetooth classic device address is bonded.
*
* @param addr Bluetooth classic device address.
Expand Down
14 changes: 14 additions & 0 deletions include/zephyr/bluetooth/hci_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,13 @@ struct bt_hci_rp_write_conn_accept_timeout {
#define BT_BREDR_SCAN_INQUIRY 0x01
#define BT_BREDR_SCAN_PAGE 0x02

#define BT_HCI_OP_WRITE_PAGE_SCAN_ACTIVITY BT_OP(BT_OGF_BASEBAND, 0x001c) /* 0x0c1c */
#define BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY BT_OP(BT_OGF_BASEBAND, 0x001e) /* 0x0c1e */
struct bt_hci_cp_write_scan_activity {
uint16_t interval;
uint16_t window;
} __packed;

#define BT_HCI_OP_READ_CLASS_OF_DEVICE BT_OP(BT_OGF_BASEBAND, 0x0023) /* 0x0c23 */
struct bt_hci_rp_read_class_of_device {
uint8_t status;
Expand Down Expand Up @@ -837,11 +844,18 @@ struct bt_hci_cp_write_current_iac_lap {
struct bt_hci_iac_lap lap[0];
} __packed;

#define BT_HCI_OP_WRITE_INQUIRY_SCAN_TYPE BT_OP(BT_OGF_BASEBAND, 0x0043) /* 0x0c43 */

#define BT_HCI_OP_WRITE_INQUIRY_MODE BT_OP(BT_OGF_BASEBAND, 0x0045) /* 0x0c45 */
struct bt_hci_cp_write_inquiry_mode {
uint8_t mode;
} __packed;

#define BT_HCI_OP_WRITE_PAGE_SCAN_TYPE BT_OP(BT_OGF_BASEBAND, 0x0047) /* 0x0c47 */
struct bt_hci_cp_write_scan_type {
uint8_t type;
} __packed;

#define BT_HCI_OP_WRITE_SSP_MODE BT_OP(BT_OGF_BASEBAND, 0x0056) /* 0x0c56 */
struct bt_hci_cp_write_ssp_mode {
uint8_t mode;
Expand Down
Loading