Bluetooth: Add BR/EDR Inquiry length to bt_br_discovery_param

This way the application can control the maximum duration of the
Inquiry. The value 0x00 (which is invalid for HCI) is still accepted
for backwards compatibility and gets mapped to the old hard-coded 0x30
value.

Change-Id: Ibc9eb86bbb6c9e45b7b351278517b4a688015195
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
This commit is contained in:
Johan Hedberg 2016-06-16 10:21:15 +03:00
commit c2a5ab1917
2 changed files with 19 additions and 5 deletions

View file

@ -285,6 +285,11 @@ typedef void bt_br_discovery_cb_t(struct bt_br_discovery_result *results,
/** BR/EDR discovery parameters */ /** BR/EDR discovery parameters */
struct bt_br_discovery_param { struct bt_br_discovery_param {
/** Maximum length of the discovery in units of 1.28 seconds.
* Valid range is 0x01 - 0x30.
*/
uint8_t length;
/** True if limited discovery procedure is to be used. */ /** True if limited discovery procedure is to be used. */
bool limited_discovery; bool limited_discovery;
}; };

View file

@ -3594,7 +3594,7 @@ struct net_buf *bt_buf_get_acl(void)
#endif /* CONFIG_BLUETOOTH_HOST_BUFFERS */ #endif /* CONFIG_BLUETOOTH_HOST_BUFFERS */
#if defined(CONFIG_BLUETOOTH_BREDR) #if defined(CONFIG_BLUETOOTH_BREDR)
static int br_start_inquiry(bool limited) static int br_start_inquiry(const struct bt_br_discovery_param *param)
{ {
const uint8_t iac[3] = { 0x33, 0x8b, 0x9e }; const uint8_t iac[3] = { 0x33, 0x8b, 0x9e };
struct bt_hci_op_inquiry *cp; struct bt_hci_op_inquiry *cp;
@ -3607,12 +3607,17 @@ static int br_start_inquiry(bool limited)
cp = net_buf_add(buf, sizeof(*cp)); cp = net_buf_add(buf, sizeof(*cp));
/* do inquiry for maximum allowed time without results limit */ if (!param->length) {
cp->length = 0x30; /* do inquiry for maximum allowed time without results limit */
cp->length = 0x30;
} else {
cp->length = param->length;
}
cp->num_rsp = 0x00; cp->num_rsp = 0x00;
memcpy(cp->lap, iac, 3); memcpy(cp->lap, iac, 3);
if (limited) { if (param->limited_discovery) {
cp->lap[0] = 0x00; cp->lap[0] = 0x00;
} }
@ -3627,11 +3632,15 @@ int bt_br_discovery_start(const struct bt_br_discovery_param *param,
BT_DBG(""); BT_DBG("");
if (param->length > 0x30) {
return -EINVAL;
}
if (atomic_test_bit(bt_dev.flags, BT_DEV_INQUIRY)) { if (atomic_test_bit(bt_dev.flags, BT_DEV_INQUIRY)) {
return -EALREADY; return -EALREADY;
} }
err = br_start_inquiry(param->limited_discovery); err = br_start_inquiry(param);
if (err) { if (err) {
return err; return err;
} }