summaryrefslogtreecommitdiffstats
path: root/net/bluetooth
diff options
context:
space:
mode:
authorArman Uguray <armansito@chromium.org>2015-03-25 18:53:41 -0700
committerMarcel Holtmann <marcel@holtmann.org>2015-03-26 03:30:28 +0100
commitb44133ff03be30b55f23036e62f403a3f7784fce (patch)
treecc03ec58ab22810289a7ff6391c69ecb68332417 /net/bluetooth
parente7a685d316e7d4b64cd3b2811687b0270d590386 (diff)
downloadop-kernel-dev-b44133ff03be30b55f23036e62f403a3f7784fce.zip
op-kernel-dev-b44133ff03be30b55f23036e62f403a3f7784fce.tar.gz
Bluetooth: Support the "discoverable" adv flag
This patch adds support for the "discoverable" flag of the Add Advertising command. Signed-off-by: Arman Uguray <armansito@chromium.org> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
Diffstat (limited to 'net/bluetooth')
-rw-r--r--net/bluetooth/mgmt.c38
1 files changed, 30 insertions, 8 deletions
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 672ff5b..c180452 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -975,13 +975,28 @@ static u8 create_default_adv_data(struct hci_dev *hdev, u8 *ptr)
static u8 create_instance_adv_data(struct hci_dev *hdev, u8 *ptr)
{
- /* TODO: Set the appropriate entries based on advertising instance flags
- * here once flags other than 0 are supported.
- */
+ u8 ad_len = 0, flags = 0;
+
+ if (hdev->adv_instance.flags & MGMT_ADV_FLAG_DISCOV)
+ flags |= LE_AD_GENERAL;
+
+ if (flags) {
+ if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))
+ flags |= LE_AD_NO_BREDR;
+
+ ptr[0] = 0x02;
+ ptr[1] = EIR_FLAGS;
+ ptr[2] = flags;
+
+ ad_len += 3;
+ ptr += 3;
+ }
+
memcpy(ptr, hdev->adv_instance.adv_data,
hdev->adv_instance.adv_data_len);
+ ad_len += hdev->adv_instance.adv_data_len;
- return hdev->adv_instance.adv_data_len;
+ return ad_len;
}
static void update_adv_data_for_instance(struct hci_request *req, u8 instance)
@@ -6556,12 +6571,16 @@ static int read_adv_features(struct sock *sk, struct hci_dev *hdev,
}
static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data,
- u8 len)
+ u8 len, bool is_adv_data)
{
u8 max_len = HCI_MAX_AD_LENGTH;
int i, cur_len;
+ bool flags_managed = false;
- /* TODO: Correctly reduce len based on adv_flags. */
+ if (is_adv_data && (adv_flags & MGMT_ADV_FLAG_DISCOV)) {
+ flags_managed = true;
+ max_len -= 3;
+ }
if (len > max_len)
return false;
@@ -6570,6 +6589,9 @@ static bool tlv_data_is_valid(struct hci_dev *hdev, u32 adv_flags, u8 *data,
for (i = 0, cur_len = 0; i < len; i += (cur_len + 1)) {
cur_len = data[i];
+ if (flags_managed && data[i + 1] == EIR_FLAGS)
+ return false;
+
/* If the current field length would exceed the total data
* length, then it's invalid.
*/
@@ -6671,9 +6693,9 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev,
goto unlock;
}
- if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len) ||
+ if (!tlv_data_is_valid(hdev, flags, cp->data, cp->adv_data_len, true) ||
!tlv_data_is_valid(hdev, flags, cp->data + cp->adv_data_len,
- cp->scan_rsp_len)) {
+ cp->scan_rsp_len, false)) {
err = mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING,
MGMT_STATUS_INVALID_PARAMS);
goto unlock;
OpenPOWER on IntegriCloud