Skip to content

Commit cc30eb6

Browse files
committed
Bluetooth: Classic: add inquiry scan param update
add BR/EDR inquiry scan param update Signed-off-by: Kai Cheng <[email protected]>
1 parent 575c243 commit cc30eb6

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

include/zephyr/bluetooth/classic/classic.h

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,48 @@ struct bt_br_page_scan_param {
389389
*/
390390
int bt_br_page_scan_update_param(const struct bt_br_page_scan_param *param);
391391

392+
struct bt_br_inquiry_scan_param {
393+
/** Inquiry scan interval in 0.625 ms units
394+
* Range: 0x0012 to 0x1000; only even values are valid.
395+
*/
396+
uint16_t interval;
397+
398+
/** Inquiry scan window in 0.625 ms units
399+
* Range: 0x0011 to 0x1000.
400+
*/
401+
uint16_t window;
402+
403+
/** Inquiry scan type. */
404+
enum bt_br_scan_type type;
405+
};
406+
407+
/**
408+
* @name Defined BR Page Scan timers
409+
* @{
410+
*/
411+
#define BT_BR_INQUIRY_SCAN_INTERVAL_DEFAULT 0x1000 /* 0x1000, 2.560s, U:0.625 */
412+
#define BT_BR_INQUIRY_SCAN_WINDOW_DEFAULT 0x0012 /* 0x0012, 11.25mss, U:0.625 */
413+
414+
/**
415+
* Helper to declare BR/EDR inquiry scan parameters inline
416+
*
417+
* @param _interval Inquiry scan interval, N * 0.625 milliseconds
418+
* @param _window Inquiry scan window, N * 0.625 milliseconds
419+
* @param _type BT_BR_SCAN_TYPE_STANDARD or BT_BR_SCAN_TYPE_INTERLACED
420+
*/
421+
#define BT_BR_INQUIRY_SCAN_PARAM(_interval, _window, _type) \
422+
((const struct bt_br_inquiry_scan_param[]) { \
423+
BT_BR_SCAN_INIT(_interval, _window, _type) \
424+
})
425+
426+
#define BT_BR_INQUIRY_SCAN_PARAM_DEFAULT \
427+
BT_BR_INQUIRY_SCAN_PARAM( \
428+
BT_BR_INQUIRY_SCAN_INTERVAL_DEFAULT, \
429+
BT_BR_INQUIRY_SCAN_WINDOW_DEFAULT, \
430+
BT_BR_SCAN_TYPE_STANDARD)
431+
432+
int bt_br_inquiry_scan_update_param(const struct bt_br_inquiry_scan_param *param);
433+
392434
/**
393435
* @brief Set the Class of Device configuration parameter of the local
394436
* BR/EDR Controller.

include/zephyr/bluetooth/hci_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,7 @@ struct bt_hci_rp_write_conn_accept_timeout {
637637
#define BT_BREDR_SCAN_PAGE 0x02
638638

639639
#define BT_HCI_OP_WRITE_PAGE_SCAN_ACTIVITY BT_OP(BT_OGF_BASEBAND, 0x001c) /* 0x0c1c */
640+
#define BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY BT_OP(BT_OGF_BASEBAND, 0x001e) /* 0x0c1e */
640641
struct bt_hci_cp_write_scan_activity {
641642
uint16_t interval;
642643
uint16_t window;
@@ -843,6 +844,8 @@ struct bt_hci_cp_write_current_iac_lap {
843844
struct bt_hci_iac_lap lap[0];
844845
} __packed;
845846

847+
#define BT_HCI_OP_WRITE_INQUIRY_SCAN_TYPE BT_OP(BT_OGF_BASEBAND, 0x0043) /* 0x0c43 */
848+
846849
#define BT_HCI_OP_WRITE_INQUIRY_MODE BT_OP(BT_OGF_BASEBAND, 0x0045) /* 0x0c45 */
847850
struct bt_hci_cp_write_inquiry_mode {
848851
uint8_t mode;

subsys/bluetooth/host/classic/br.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,6 +1375,38 @@ int bt_br_page_scan_update_param(const struct bt_br_page_scan_param *param)
13751375
return 0;
13761376
}
13771377

1378+
int bt_br_inquiry_scan_update_param(const struct bt_br_inquiry_scan_param *param)
1379+
{
1380+
int err;
1381+
1382+
if (param->interval < 0x0012 || param->interval > 0x1000) {
1383+
return -EINVAL;
1384+
}
1385+
1386+
if (param->window < 0x0011 || param->window > 0x1000) {
1387+
return -EINVAL;
1388+
}
1389+
1390+
if (param->interval < param->window) {
1391+
return -EINVAL;
1392+
}
1393+
1394+
err = bt_br_write_scan_activity(BT_HCI_OP_WRITE_INQUIRY_SCAN_ACTIVITY,
1395+
param->interval, param->window);
1396+
if (err) {
1397+
LOG_ERR("write inquiry scan activity failed (err %d)", err);
1398+
return err;
1399+
}
1400+
1401+
err = bt_br_write_scan_type(BT_HCI_OP_WRITE_INQUIRY_SCAN_TYPE, param->type);
1402+
if (err) {
1403+
LOG_ERR("write inquiry scan type failed (err %d)", err);
1404+
return err;
1405+
}
1406+
1407+
return 0;
1408+
}
1409+
13781410
int bt_br_set_class_of_device(uint32_t cod)
13791411
{
13801412
int err;

0 commit comments

Comments
 (0)