This patch series adds broadcaster and observer functionality.
For the userspace, we are updating our branch and we will send it in s few
days.
Aloisio Almeida Jr (10):
Bluetooth: Set advertising parameters on LE setup
Bluetooth: Add set controller data MGMT command
Bluetooth: Add set broadcaster MGMT command
Bluetooth: Advertise controller data in broadcaster mode
Bluetooth: Stop to acquire hdev lock inside hci_update_ad
Bluetooth: Enable on-the-fly update of broadcast data
Bluetooth: Enable support for broadcaster mode when powered off.
Bluetooth: Refactor le scan helpers to enable observer support
Bluetooth: Add set observer MGMT command
Bluetooth: Enable support for observer mode when powered off.
Jefferson Delfes (2):
Bluetooth: Add HCI command to set advertising parameters
Bluetooth: Add unset controller data MGMT command
include/net/bluetooth/hci.h | 19 +++
include/net/bluetooth/hci_core.h | 42 ++++-
include/net/bluetooth/mgmt.h | 21 +++
net/bluetooth/hci_core.c | 183 ++++++++++++++++-----
net/bluetooth/hci_event.c | 121 +++++++++-----
net/bluetooth/mgmt.c | 335 +++++++++++++++++++++++++++++++++++++--
6 files changed, 628 insertions(+), 93 deletions(-)
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
We have to enable le scan in mgmt_powered if observer mode is on.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
net/bluetooth/mgmt.c | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index e960da2..04407d6 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2848,8 +2848,20 @@ static int set_observer_le(struct sock *sk, struct hci_dev *hdev, u8 enable)
hci_dev_lock(hdev);
if (!hdev_is_powered(hdev)) {
- err = cmd_status(sk, hdev->id, MGMT_OP_SET_OBSERVER,
- MGMT_STATUS_NOT_POWERED);
+ bool changed = false;
+
+ if (enable != test_bit(HCI_OBSERVER, &hdev->dev_flags)) {
+ change_bit(HCI_OBSERVER, &hdev->dev_flags);
+ changed = true;
+ }
+
+ err = send_settings_rsp(sk, MGMT_OP_SET_OBSERVER, hdev);
+ if (err < 0)
+ goto unlock;
+
+ if (changed)
+ err = new_settings(hdev, sk);
+
goto unlock;
}
@@ -3156,6 +3168,13 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE,
sizeof(enable), &enable);
}
+
+ if (test_bit(HCI_OBSERVER, &hdev->dev_flags)) {
+ hci_le_scan(hdev, LE_SCAN_TYPE_PASSIVE,
+ LE_SCAN_INT,
+ LE_SCAN_WIN, LE_SCAN_NO_TIMEOUT,
+ LE_SCAN_REQ_REASON_OBSERVER);
+ }
}
if (lmp_bredr_capable(hdev)) {
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
This command will enable or disable observer mode.
If LE_ENABLED is set the HCI_OP_LE_SET_SCAN_PARAMS and HCI_OP_LE_SET_SCAN_ENABLE
commands will be sent. Observer will perform a passive scan with no timeout.
If discovery is required when observer is enabled, le scan is restarted in
active mode.
If observer is enabled when discovery finishes, passive le scan
is enabled.
If observer mode is required when discovery is on going, the le scan mode does
not change until the end of discovery process.
Some changes on device lock are needed. Moving hci_dev_lock from
mgmt_interleaved_discovery to hci_cc_le_set_scan_enable.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 5 ++
include/net/bluetooth/mgmt.h | 3 +
net/bluetooth/hci_core.c | 18 ++++-
net/bluetooth/hci_event.c | 50 +++++++-------
net/bluetooth/mgmt.c | 137 ++++++++++++++++++++++++++++++++++++---
6 files changed, 179 insertions(+), 35 deletions(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index efbdd3d..c17bb9a 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -122,6 +122,7 @@ enum {
HCI_PENDING_CLASS,
HCI_PERIODIC_INQ,
HCI_BROADCASTER,
+ HCI_OBSERVER,
};
/* HCI ioctl defines */
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 8731add..a82d6be 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -55,6 +55,8 @@ struct inquiry_entry {
struct inquiry_data data;
};
+#define hdev_is_in_discovery(hdev) (hdev->discovery.state != DISCOVERY_STOPPED)
+
struct discovery_state {
int type;
enum {
@@ -125,7 +127,9 @@ struct le_scan_params {
};
enum {
+ LE_SCAN_REQ_REASON_RESET,
LE_SCAN_REQ_REASON_DISCOVERY,
+ LE_SCAN_REQ_REASON_OBSERVER,
};
struct broadcast_data {
@@ -1136,6 +1140,7 @@ int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
int mgmt_set_broadcaster_complete(struct hci_dev *hdev, bool changed,
u8 status);
+int mgmt_set_observer_complete(struct hci_dev *hdev, u8 enable, u8 status);
int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
u8 ssp, u8 *eir, u16 eir_len);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index bd64816..13936ab 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -93,6 +93,7 @@ struct mgmt_rp_read_index_list {
#define MGMT_SETTING_HS 0x00000100
#define MGMT_SETTING_LE 0x00000200
#define MGMT_SETTING_BROADCASTER 0x00000400
+#define MGMT_SETTING_OBSERVER 0x00000800
#define MGMT_OP_READ_INFO 0x0004
#define MGMT_READ_INFO_SIZE 0
@@ -368,6 +369,8 @@ struct mgmt_cp_unset_controller_data {
#define MGMT_OP_SET_BROADCASTER 0x002B
+#define MGMT_OP_SET_OBSERVER 0x002C
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 9b6c9e4..32bf2eb 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1672,14 +1672,28 @@ static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
BT_DBG("%s", hdev->name);
- if (test_bit(HCI_LE_SCAN, &hdev->dev_flags))
+ if (test_bit(HCI_LE_SCAN, &hdev->dev_flags) &&
+ reason == LE_SCAN_REQ_REASON_OBSERVER)
return -EINPROGRESS;
+ memset(&cp, 0, sizeof(cp));
+
+ if (test_bit(HCI_LE_SCAN, &hdev->dev_flags) &&
+ reason == LE_SCAN_REQ_REASON_DISCOVERY) {
+ hci_dev_lock(hdev);
+ hdev->le_scan_req_reason = LE_SCAN_REQ_REASON_RESET;
+ hci_dev_unlock(hdev);
+
+ err = hci_request(hdev, le_scan_enable_req, (unsigned long) &cp,
+ timeo);
+ if (err)
+ return err;
+ }
+
param.type = type;
param.interval = interval;
param.window = window;
- memset(&cp, 0, sizeof(cp));
cp.enable = 1;
if (reason == LE_SCAN_REQ_REASON_DISCOVERY)
cp.filter_dup = 1;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index b5eb89a..ede0b78 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1277,42 +1277,42 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
if (!cp)
return;
- switch (cp->enable) {
- case LE_SCANNING_ENABLED:
- hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_ENABLE, status);
+ hci_dev_lock(hdev);
- if (status) {
- hci_dev_lock(hdev);
- mgmt_start_discovery_failed(hdev, status);
- hci_dev_unlock(hdev);
- return;
- }
+ if (!status) {
+ if (cp->enable)
+ set_bit(HCI_LE_SCAN, &hdev->dev_flags);
+ else
+ clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
+ }
- set_bit(HCI_LE_SCAN, &hdev->dev_flags);
+ if (hdev->le_scan_req_reason == LE_SCAN_REQ_REASON_RESET)
+ goto unlock;
- hci_dev_lock(hdev);
- hci_discovery_set_state(hdev, DISCOVERY_FINDING);
- hci_dev_unlock(hdev);
+ if (hdev->le_scan_req_reason == LE_SCAN_REQ_REASON_OBSERVER) {
+ mgmt_set_observer_complete(hdev, cp->enable, status);
+ goto unlock;
+ }
+
+ switch (cp->enable) {
+ case LE_SCANNING_ENABLED:
+ if (status)
+ mgmt_start_discovery_failed(hdev, status);
+ else
+ hci_discovery_set_state(hdev, DISCOVERY_FINDING);
break;
case LE_SCANNING_DISABLED:
if (status) {
- hci_dev_lock(hdev);
mgmt_stop_discovery_failed(hdev, status);
- hci_dev_unlock(hdev);
- return;
+ goto unlock;
}
- clear_bit(HCI_LE_SCAN, &hdev->dev_flags);
-
if (hdev->discovery.type == DISCOV_TYPE_INTERLEAVED &&
- hdev->discovery.state == DISCOVERY_FINDING) {
+ hdev->discovery.state == DISCOVERY_FINDING)
mgmt_interleaved_discovery(hdev);
- } else {
- hci_dev_lock(hdev);
+ else
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
- hci_dev_unlock(hdev);
- }
break;
@@ -1320,6 +1320,10 @@ static void hci_cc_le_set_scan_enable(struct hci_dev *hdev,
BT_ERR("Used reserved LE_Scan_Enable param %d", cp->enable);
break;
}
+
+unlock:
+ hci_req_complete(hdev, HCI_OP_LE_SET_SCAN_ENABLE, status);
+ hci_dev_unlock(hdev);
}
static void hci_cc_le_ltk_reply(struct hci_dev *hdev, struct sk_buff *skb)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index bed28e4..e960da2 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -106,11 +106,13 @@ static const u16 mgmt_events[] = {
* These LE scan and inquiry parameters were chosen according to LE General
* Discovery Procedure specification.
*/
-#define LE_SCAN_TYPE 0x01
+#define LE_SCAN_TYPE_PASSIVE 0x00
+#define LE_SCAN_TYPE_ACTIVE 0x01
#define LE_SCAN_WIN 0x12
#define LE_SCAN_INT 0x12
#define LE_SCAN_TIMEOUT_LE_ONLY 10240 /* TGAP(gen_disc_scan_min) */
#define LE_SCAN_TIMEOUT_BREDR_LE 5120 /* TGAP(100)/2 */
+#define LE_SCAN_NO_TIMEOUT -1 /* Observer role */
#define INQUIRY_LEN_BREDR 0x08 /* TGAP(100) */
#define INQUIRY_LEN_BREDR_LE 0x04 /* TGAP(100)/2 */
@@ -395,6 +397,7 @@ static u32 get_supported_settings(struct hci_dev *hdev)
if (lmp_le_capable(hdev)) {
settings |= MGMT_SETTING_LE;
settings |= MGMT_SETTING_BROADCASTER;
+ settings |= MGMT_SETTING_OBSERVER;
}
return settings;
@@ -425,6 +428,9 @@ static u32 get_current_settings(struct hci_dev *hdev)
if (test_bit(HCI_BROADCASTER, &hdev->dev_flags))
settings |= MGMT_SETTING_BROADCASTER;
+ if (test_bit(HCI_OBSERVER, &hdev->dev_flags))
+ settings |= MGMT_SETTING_OBSERVER;
+
if (test_bit(HCI_LINK_SECURITY, &hdev->dev_flags))
settings |= MGMT_SETTING_LINK_SECURITY;
@@ -2318,14 +2324,10 @@ int mgmt_interleaved_discovery(struct hci_dev *hdev)
BT_DBG("%s", hdev->name);
- hci_dev_lock(hdev);
-
err = hci_do_inquiry(hdev, INQUIRY_LEN_BREDR_LE);
if (err < 0)
hci_discovery_set_state(hdev, DISCOVERY_STOPPED);
- hci_dev_unlock(hdev);
-
return err;
}
@@ -2352,7 +2354,7 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
goto failed;
}
- if (hdev->discovery.state != DISCOVERY_STOPPED) {
+ if (hdev_is_in_discovery(hdev)) {
err = cmd_status(sk, hdev->id, MGMT_OP_START_DISCOVERY,
MGMT_STATUS_BUSY);
goto failed;
@@ -2376,8 +2378,9 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
case DISCOV_TYPE_LE:
if (lmp_host_le_capable(hdev))
- err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT,
- LE_SCAN_WIN, LE_SCAN_TIMEOUT_LE_ONLY,
+ err = hci_le_scan(hdev, LE_SCAN_TYPE_ACTIVE,
+ LE_SCAN_INT, LE_SCAN_WIN,
+ LE_SCAN_TIMEOUT_LE_ONLY,
LE_SCAN_REQ_REASON_DISCOVERY);
else
err = -ENOTSUPP;
@@ -2385,8 +2388,9 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
case DISCOV_TYPE_INTERLEAVED:
if (lmp_host_le_capable(hdev) && lmp_bredr_capable(hdev))
- err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT,
- LE_SCAN_WIN, LE_SCAN_TIMEOUT_BREDR_LE,
+ err = hci_le_scan(hdev, LE_SCAN_TYPE_ACTIVE,
+ LE_SCAN_INT, LE_SCAN_WIN,
+ LE_SCAN_TIMEOUT_BREDR_LE,
LE_SCAN_REQ_REASON_DISCOVERY);
else
err = -ENOTSUPP;
@@ -2834,6 +2838,77 @@ static int set_broadcaster(struct sock *sk, struct hci_dev *hdev, void *data,
return set_broadcaster_le(sk, hdev, cp->val);
}
+static int set_observer_le(struct sock *sk, struct hci_dev *hdev, u8 enable)
+{
+ struct pending_cmd *cmd;
+ int err;
+
+ BT_DBG("%s enable:%i", hdev->name, enable);
+
+ hci_dev_lock(hdev);
+
+ if (!hdev_is_powered(hdev)) {
+ err = cmd_status(sk, hdev->id, MGMT_OP_SET_OBSERVER,
+ MGMT_STATUS_NOT_POWERED);
+ goto unlock;
+ }
+
+ if (mgmt_pending_find(MGMT_OP_SET_OBSERVER, hdev)) {
+ err = cmd_status(sk, hdev->id, MGMT_OP_SET_OBSERVER,
+ MGMT_STATUS_BUSY);
+ goto unlock;
+ }
+
+ if (enable == test_bit(HCI_OBSERVER, &hdev->dev_flags)) {
+ err = send_settings_rsp(sk, MGMT_OP_SET_OBSERVER, hdev);
+ goto unlock;
+ }
+
+ if (hdev_is_in_discovery(hdev)) {
+ change_bit(HCI_OBSERVER, &hdev->dev_flags);
+ err = send_settings_rsp(sk, MGMT_OP_SET_OBSERVER, hdev);
+ if (err < 0)
+ goto unlock;
+
+ err = new_settings(hdev, sk);
+ goto unlock;
+ }
+
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_OBSERVER, hdev, NULL, 0);
+ if (!cmd) {
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ if (enable)
+ err = hci_le_scan(hdev, LE_SCAN_TYPE_PASSIVE, LE_SCAN_INT,
+ LE_SCAN_WIN, LE_SCAN_NO_TIMEOUT,
+ LE_SCAN_REQ_REASON_OBSERVER);
+ else
+ err = hci_cancel_le_scan(hdev, LE_SCAN_REQ_REASON_OBSERVER);
+
+ if (err < 0)
+ mgmt_pending_remove(cmd);
+
+unlock:
+ hci_dev_unlock(hdev);
+ return err;
+}
+
+static int set_observer(struct sock *sk, struct hci_dev *hdev, void *data,
+ u16 len)
+{
+ struct mgmt_mode *cp = data;
+
+ BT_DBG("%s val:%i", hdev->name, cp->val);
+
+ if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_OBSERVER,
+ MGMT_STATUS_NOT_SUPPORTED);
+
+ return set_observer_le(sk, hdev, cp->val);
+}
+
static const struct mgmt_handler {
int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
u16 data_len);
@@ -2884,6 +2959,7 @@ static const struct mgmt_handler {
{ set_controller_data, true, MGMT_SET_CONTROLLER_DATA_SIZE },
{ unset_controller_data, false, MGMT_UNSET_CONTROLLER_DATA_SIZE },
{ set_broadcaster, false, MGMT_SETTING_SIZE },
+ { set_observer, false, MGMT_SETTING_SIZE },
};
@@ -3777,6 +3853,42 @@ int mgmt_set_broadcaster_complete(struct hci_dev *hdev, bool changed, u8 status)
return err;
}
+int mgmt_set_observer_complete(struct hci_dev *hdev, u8 enable, u8 status)
+{
+ struct pending_cmd *cmd;
+ struct cmd_lookup match = { NULL, hdev };
+ bool changed = false;
+ int err = 0;
+
+ cmd = mgmt_pending_find(MGMT_OP_SET_OBSERVER, hdev);
+ if (!cmd)
+ return -ENOENT;
+
+ if (status) {
+ u8 mgmt_err = mgmt_status(status);
+ cmd_status_rsp(cmd, &mgmt_err);
+ return err;
+ }
+
+ if (enable) {
+ if (!test_and_set_bit(HCI_OBSERVER, &hdev->dev_flags))
+ changed = true;
+ } else {
+ if (test_and_clear_bit(HCI_OBSERVER, &hdev->dev_flags))
+ changed = true;
+ }
+
+ settings_rsp(cmd, &match);
+
+ if (changed)
+ err = new_settings(hdev, match.sk);
+
+ if (match.sk)
+ sock_put(match.sk);
+
+ return err;
+}
+
int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, u8
ssp, u8 *eir, u16 eir_len)
@@ -3893,6 +4005,11 @@ int mgmt_discovering(struct hci_dev *hdev, u8 discovering)
mgmt_pending_remove(cmd);
}
+ if (!discovering && test_bit(HCI_OBSERVER, &hdev->dev_flags))
+ hci_le_scan(hdev, LE_SCAN_TYPE_PASSIVE, LE_SCAN_INT,
+ LE_SCAN_WIN, LE_SCAN_NO_TIMEOUT,
+ LE_SCAN_REQ_REASON_OBSERVER);
+
memset(&ev, 0, sizeof(ev));
ev.type = hdev->discovery.type;
ev.discovering = discovering;
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
It was added a parameter called 'reason' to le scan helpers (hci_do_le_scan and
hci_cancel_le_scan). Distinguishing the reason to enbale/disable le scan will be
important when both discovery and observer are implemented.
'reason' was also added do hdev structure (hdev.le_scan_req_reason) in order
to make hci_cc_le_set_scan_enable to behave correctly.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
include/net/bluetooth/hci_core.h | 11 +++++--
net/bluetooth/hci_core.c | 63 +++++++++++++++++++++++++---------------
net/bluetooth/mgmt.c | 10 ++++---
3 files changed, 54 insertions(+), 30 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index d5fd56a..8731add 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -121,6 +121,11 @@ struct le_scan_params {
u16 interval;
u16 window;
int timeout;
+ u8 reason;
+};
+
+enum {
+ LE_SCAN_REQ_REASON_DISCOVERY,
};
struct broadcast_data {
@@ -289,6 +294,7 @@ struct hci_dev {
struct work_struct le_scan;
struct le_scan_params le_scan_params;
+ __u8 le_scan_req_reason;
__s8 adv_tx_power;
__u8 adv_data[HCI_MAX_AD_LENGTH];
@@ -1180,9 +1186,10 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __u8 rand[8],
__u8 ltk[16]);
int hci_do_inquiry(struct hci_dev *hdev, u8 length);
int hci_cancel_inquiry(struct hci_dev *hdev);
+
int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
- int timeout);
-int hci_cancel_le_scan(struct hci_dev *hdev);
+ int timeout, u8 reason);
+int hci_cancel_le_scan(struct hci_dev *hdev, u8 reason);
u8 bdaddr_to_le(u8 bdaddr_type);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 518c916..9b6c9e4 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1654,20 +1654,20 @@ static void le_scan_param_req(struct hci_dev *hdev, unsigned long opt)
static void le_scan_enable_req(struct hci_dev *hdev, unsigned long opt)
{
- struct hci_cp_le_set_scan_enable cp;
+ struct hci_cp_le_set_scan_enable *cp;
- memset(&cp, 0, sizeof(cp));
- cp.enable = 1;
- cp.filter_dup = 1;
+ cp = (struct hci_cp_le_set_scan_enable *) opt;
- hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
+ hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE,
+ sizeof(struct hci_cp_le_set_scan_enable), cp);
}
static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
- u16 window, int timeout)
+ u16 window, int timeout, u8 reason)
{
long timeo = msecs_to_jiffies(3000);
struct le_scan_params param;
+ struct hci_cp_le_set_scan_enable cp;
int err;
BT_DBG("%s", hdev->name);
@@ -1679,38 +1679,52 @@ static int hci_do_le_scan(struct hci_dev *hdev, u8 type, u16 interval,
param.interval = interval;
param.window = window;
+ memset(&cp, 0, sizeof(cp));
+ cp.enable = 1;
+ if (reason == LE_SCAN_REQ_REASON_DISCOVERY)
+ cp.filter_dup = 1;
+
+ hci_dev_lock(hdev);
+ hdev->le_scan_req_reason = reason;
+ hci_dev_unlock(hdev);
+
hci_req_lock(hdev);
err = __hci_request(hdev, le_scan_param_req, (unsigned long) ¶m,
timeo);
- if (!err)
- err = __hci_request(hdev, le_scan_enable_req, 0, timeo);
+ if (err)
+ goto unlock;
- hci_req_unlock(hdev);
-
- if (err < 0)
- return err;
+ err = __hci_request(hdev, le_scan_enable_req, (unsigned long) &cp,
+ timeo);
+ if (err)
+ goto unlock;
- schedule_delayed_work(&hdev->le_scan_disable,
- msecs_to_jiffies(timeout));
+ if (timeout > 0)
+ schedule_delayed_work(&hdev->le_scan_disable,
+ msecs_to_jiffies(timeout));
- return 0;
+unlock:
+ hci_req_unlock(hdev);
+ return err;
}
-int hci_cancel_le_scan(struct hci_dev *hdev)
+int hci_cancel_le_scan(struct hci_dev *hdev, u8 reason)
{
+ struct hci_cp_le_set_scan_enable cp;
+
BT_DBG("%s", hdev->name);
if (!test_bit(HCI_LE_SCAN, &hdev->dev_flags))
return -EALREADY;
- if (cancel_delayed_work(&hdev->le_scan_disable)) {
- struct hci_cp_le_set_scan_enable cp;
+ if (reason == LE_SCAN_REQ_REASON_DISCOVERY)
+ if (!cancel_delayed_work(&hdev->le_scan_disable))
+ return 0;
- /* Send HCI command to disable LE Scan */
- memset(&cp, 0, sizeof(cp));
- hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
- }
+ /* Send HCI command to disable LE Scan */
+ memset(&cp, 0, sizeof(cp));
+ hci_send_cmd(hdev, HCI_OP_LE_SET_SCAN_ENABLE, sizeof(cp), &cp);
return 0;
}
@@ -1736,11 +1750,11 @@ static void le_scan_work(struct work_struct *work)
BT_DBG("%s", hdev->name);
hci_do_le_scan(hdev, param->type, param->interval, param->window,
- param->timeout);
+ param->timeout, param->reason);
}
int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
- int timeout)
+ int timeout, u8 reason)
{
struct le_scan_params *param = &hdev->le_scan_params;
@@ -1756,6 +1770,7 @@ int hci_le_scan(struct hci_dev *hdev, u8 type, u16 interval, u16 window,
param->interval = interval;
param->window = window;
param->timeout = timeout;
+ param->reason = reason;
queue_work(system_long_wq, &hdev->le_scan);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 805ae3b..bed28e4 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2377,7 +2377,8 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
case DISCOV_TYPE_LE:
if (lmp_host_le_capable(hdev))
err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT,
- LE_SCAN_WIN, LE_SCAN_TIMEOUT_LE_ONLY);
+ LE_SCAN_WIN, LE_SCAN_TIMEOUT_LE_ONLY,
+ LE_SCAN_REQ_REASON_DISCOVERY);
else
err = -ENOTSUPP;
break;
@@ -2385,8 +2386,8 @@ static int start_discovery(struct sock *sk, struct hci_dev *hdev,
case DISCOV_TYPE_INTERLEAVED:
if (lmp_host_le_capable(hdev) && lmp_bredr_capable(hdev))
err = hci_le_scan(hdev, LE_SCAN_TYPE, LE_SCAN_INT,
- LE_SCAN_WIN,
- LE_SCAN_TIMEOUT_BREDR_LE);
+ LE_SCAN_WIN, LE_SCAN_TIMEOUT_BREDR_LE,
+ LE_SCAN_REQ_REASON_DISCOVERY);
else
err = -ENOTSUPP;
break;
@@ -2443,7 +2444,8 @@ static int stop_discovery(struct sock *sk, struct hci_dev *hdev, void *data,
if (test_bit(HCI_INQUIRY, &hdev->flags))
err = hci_cancel_inquiry(hdev);
else
- err = hci_cancel_le_scan(hdev);
+ err = hci_cancel_le_scan(hdev,
+ LE_SCAN_REQ_REASON_DISCOVERY);
break;
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
We have to enable advertising in mgmt_powered if broadcaster mode is on.
We also need to update the advertising data in mgmt_powered if brodcaster
mode is on.
As the advertising data is already being updated on mgmt_powered function,
we don't need to update it also in hci_dev_open.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
net/bluetooth/hci_core.c | 3 ---
net/bluetooth/mgmt.c | 38 ++++++++++++++++++++++++--------------
2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index c692b14..518c916 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -764,9 +764,6 @@ int hci_dev_open(__u16 dev)
hci_dev_hold(hdev);
set_bit(HCI_UP, &hdev->flags);
hci_notify(hdev, HCI_DEV_UP);
- hci_dev_lock(hdev);
- __hci_update_ad(hdev);
- hci_dev_unlock(hdev);
if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
mgmt_valid_hdev(hdev)) {
hci_dev_lock(hdev);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index e910b11..805ae3b 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2720,12 +2720,6 @@ static int set_controller_data(struct sock *sk, struct hci_dev *hdev,
hci_dev_lock(hdev);
- if (!hdev_is_powered(hdev)) {
- hci_dev_unlock(hdev);
- return cmd_status(sk, hdev->id, MGMT_OP_SET_CONTROLLER_DATA,
- MGMT_STATUS_NOT_POWERED);
- }
-
room = HCI_MAX_AD_LENGTH - hdev->broadcast_data_len;
if (sizeof(cp->length) + sizeof(cp->type) + cp->length > room) {
hci_dev_unlock(hdev);
@@ -2757,12 +2751,6 @@ static int unset_controller_data(struct sock *sk, struct hci_dev *hdev,
hci_dev_lock(hdev);
- if (!hdev_is_powered(hdev)) {
- hci_dev_unlock(hdev);
- return cmd_status(sk, hdev->id, MGMT_OP_UNSET_CONTROLLER_DATA,
- MGMT_STATUS_NOT_POWERED);
- }
-
removed = hci_broadcast_data_remove(hdev, cp->type);
if (removed && test_bit(HCI_BROADCASTER, &hdev->dev_flags))
@@ -2784,8 +2772,20 @@ static int set_broadcaster_le(struct sock *sk, struct hci_dev *hdev, u8 enable)
hci_dev_lock(hdev);
if (!hdev_is_powered(hdev)) {
- err = cmd_status(sk, hdev->id, MGMT_OP_SET_BROADCASTER,
- MGMT_STATUS_NOT_POWERED);
+ bool changed = false;
+
+ if (enable != test_bit(HCI_BROADCASTER, &hdev->dev_flags)) {
+ change_bit(HCI_BROADCASTER, &hdev->dev_flags);
+ changed = true;
+ }
+
+ err = send_settings_rsp(sk, MGMT_OP_SET_BROADCASTER, hdev);
+ if (err < 0)
+ goto unlock;
+
+ if (changed)
+ err = new_settings(hdev, sk);
+
goto unlock;
}
@@ -3068,6 +3068,16 @@ int mgmt_powered(struct hci_dev *hdev, u8 powered)
hci_send_cmd(hdev,
HCI_OP_WRITE_LE_HOST_SUPPORTED,
sizeof(cp), &cp);
+
+ __hci_update_ad(hdev);
+
+ if (test_bit(HCI_BROADCASTER, &hdev->dev_flags)) {
+ u8 enable = 1;
+ hdev->le_adv_req_reason =
+ LE_ADV_REQ_REASON_BROADCASTER;
+ hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE,
+ sizeof(enable), &enable);
+ }
}
if (lmp_bredr_capable(hdev)) {
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
The broadcast data can be updated with no need to re-enable broadcaster
mode.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
net/bluetooth/mgmt.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 608e81af..e910b11 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2738,6 +2738,9 @@ static int set_controller_data(struct sock *sk, struct hci_dev *hdev,
hci_broadcast_data_add(hdev, cp->flags, cp->type, cp->length, cp->data);
+ if (test_bit(HCI_BROADCASTER, &hdev->dev_flags))
+ __hci_update_ad(hdev);
+
hci_dev_unlock(hdev);
return cmd_complete(sk, hdev->id, MGMT_OP_SET_CONTROLLER_DATA, 0, NULL,
@@ -2748,6 +2751,7 @@ static int unset_controller_data(struct sock *sk, struct hci_dev *hdev,
void *data, u16 len)
{
struct mgmt_cp_unset_controller_data *cp = data;
+ int removed;
BT_DBG("%s type:0x%02x", hdev->name, cp->type);
@@ -2759,7 +2763,10 @@ static int unset_controller_data(struct sock *sk, struct hci_dev *hdev,
MGMT_STATUS_NOT_POWERED);
}
- hci_broadcast_data_remove(hdev, cp->type);
+ removed = hci_broadcast_data_remove(hdev, cp->type);
+
+ if (removed && test_bit(HCI_BROADCASTER, &hdev->dev_flags))
+ __hci_update_ad(hdev);
hci_dev_unlock(hdev);
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
In order to enable broadcaster mode even in power off state, hci_update_ad
must be called in mgmt_powered function, that already has the lock.
Removing the locking logic from inside this function is not a big deal as
most of the functions that already call hci_update_ad also have the lock.
The function was renamed to __hci_update_ad to follow the convention.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
include/net/bluetooth/hci_core.h | 2 +-
net/bluetooth/hci_core.c | 23 ++++++++---------------
net/bluetooth/hci_event.c | 19 +++++++++++--------
3 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 56af0fd..d5fd56a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -754,7 +754,7 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
u8 *randomizer);
int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr);
-int hci_update_ad(struct hci_dev *hdev);
+int __hci_update_ad(struct hci_dev *hdev);
void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 5ba9fad..c692b14 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -678,18 +678,14 @@ static u8 create_ad_broadcast(struct hci_dev *hdev, u8 *ptr)
return len;
}
-int hci_update_ad(struct hci_dev *hdev)
+int __hci_update_ad(struct hci_dev *hdev)
{
struct hci_cp_le_set_adv_data cp;
u8 len;
int err;
- hci_dev_lock(hdev);
-
- if (!lmp_le_capable(hdev)) {
- err = -EINVAL;
- goto unlock;
- }
+ if (!lmp_le_capable(hdev))
+ return -EINVAL;
memset(&cp, 0, sizeof(cp));
@@ -699,10 +695,8 @@ int hci_update_ad(struct hci_dev *hdev)
len = create_ad(hdev, cp.data);
if (hdev->adv_data_len == len &&
- memcmp(cp.data, hdev->adv_data, len) == 0) {
- err = 0;
- goto unlock;
- }
+ memcmp(cp.data, hdev->adv_data, len) == 0)
+ return 0;
memcpy(hdev->adv_data, cp.data, sizeof(cp.data));
hdev->adv_data_len = len;
@@ -710,9 +704,6 @@ int hci_update_ad(struct hci_dev *hdev)
cp.length = len;
err = hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_DATA, sizeof(cp), &cp);
-unlock:
- hci_dev_unlock(hdev);
-
return err;
}
@@ -773,7 +764,9 @@ int hci_dev_open(__u16 dev)
hci_dev_hold(hdev);
set_bit(HCI_UP, &hdev->flags);
hci_notify(hdev, HCI_DEV_UP);
- hci_update_ad(hdev);
+ hci_dev_lock(hdev);
+ __hci_update_ad(hdev);
+ hci_dev_unlock(hdev);
if (!test_bit(HCI_SETUP, &hdev->dev_flags) &&
mgmt_valid_hdev(hdev)) {
hci_dev_lock(hdev);
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 46f76d6..b5eb89a 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -227,10 +227,10 @@ static void hci_cc_write_local_name(struct hci_dev *hdev, struct sk_buff *skb)
else if (!status)
memcpy(hdev->dev_name, sent, HCI_MAX_NAME_LENGTH);
- hci_dev_unlock(hdev);
-
if (!status && !test_bit(HCI_INIT, &hdev->flags))
- hci_update_ad(hdev);
+ __hci_update_ad(hdev);
+
+ hci_dev_unlock(hdev);
hci_req_complete(hdev, HCI_OP_WRITE_LOCAL_NAME, status);
}
@@ -1110,8 +1110,11 @@ static void hci_cc_le_read_adv_tx_power(struct hci_dev *hdev,
if (!rp->status) {
hdev->adv_tx_power = rp->tx_power;
- if (!test_bit(HCI_INIT, &hdev->flags))
- hci_update_ad(hdev);
+ if (!test_bit(HCI_INIT, &hdev->flags)) {
+ hci_dev_lock(hdev);
+ __hci_update_ad(hdev);
+ hci_dev_unlock(hdev);
+ }
}
hci_req_complete(hdev, HCI_OP_LE_READ_ADV_TX_POWER, rp->status);
@@ -1238,10 +1241,10 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
}
}
- hci_dev_unlock(hdev);
-
if (!test_bit(HCI_INIT, &hdev->flags))
- hci_update_ad(hdev);
+ __hci_update_ad(hdev);
+
+ hci_dev_unlock(hdev);
hci_req_complete(hdev, HCI_OP_LE_SET_ADV_ENABLE, status);
}
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
In broadcaster mode, the adapter must advertise the data set by user in
set_controller_data.
According to the spec, the flags field must be ommited if its value is zero.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
net/bluetooth/hci_core.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index d015e1f..5ba9fad 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -654,6 +654,30 @@ static u8 create_ad(struct hci_dev *hdev, u8 *ptr)
return ad_len;
}
+static u8 create_ad_broadcast(struct hci_dev *hdev, u8 *ptr)
+{
+ u16 len = 0;
+ struct broadcast_data *d;
+
+ list_for_each_entry(d, &hdev->broadcast_data, list) {
+ u8 entry_len = sizeof(d->length) + sizeof(d->type) + d->length;
+
+ if (len + entry_len > HCI_MAX_AD_LENGTH) {
+ BT_DBG("Controller data bigger than adv data slot");
+ return len;
+ }
+
+ ptr[0] = sizeof(d->type) + d->length;
+ ptr[1] = d->type;
+ memcpy(&ptr[2], d->data, d->length);
+
+ len += entry_len;
+ ptr += entry_len;
+ }
+
+ return len;
+}
+
int hci_update_ad(struct hci_dev *hdev)
{
struct hci_cp_le_set_adv_data cp;
@@ -669,7 +693,10 @@ int hci_update_ad(struct hci_dev *hdev)
memset(&cp, 0, sizeof(cp));
- len = create_ad(hdev, cp.data);
+ if (test_bit(HCI_BROADCASTER, &hdev->dev_flags))
+ len = create_ad_broadcast(hdev, cp.data);
+ else
+ len = create_ad(hdev, cp.data);
if (hdev->adv_data_len == len &&
memcmp(cp.data, hdev->adv_data, len) == 0) {
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
This command will enable or disable broadcaster mode. Data can be added
with set_controller_data command.
If LE_ENABLED is set, the HCI_OP_LE_SET_ADV_ENABLE command will be sent.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
include/net/bluetooth/hci.h | 1 +
include/net/bluetooth/hci_core.h | 8 ++++
include/net/bluetooth/mgmt.h | 3 ++
net/bluetooth/hci_event.c | 28 +++++++++---
net/bluetooth/mgmt.c | 93 +++++++++++++++++++++++++++++++++++++++-
5 files changed, 127 insertions(+), 6 deletions(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index a89ff01..efbdd3d 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -121,6 +121,7 @@ enum {
HCI_LINK_SECURITY,
HCI_PENDING_CLASS,
HCI_PERIODIC_INQ,
+ HCI_BROADCASTER,
};
/* HCI ioctl defines */
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index cf8d125..56af0fd 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -131,6 +131,10 @@ struct broadcast_data {
u8 data[0];
};
+enum {
+ LE_ADV_REQ_REASON_BROADCASTER,
+};
+
#define HCI_MAX_SHORT_NAME_LENGTH 10
struct amp_assoc {
@@ -293,6 +297,8 @@ struct hci_dev {
struct list_head broadcast_data;
__u16 broadcast_data_len;
+ __u8 le_adv_req_reason;
+
int (*open)(struct hci_dev *hdev);
int (*close)(struct hci_dev *hdev);
int (*flush)(struct hci_dev *hdev);
@@ -1122,6 +1128,8 @@ int mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status);
int mgmt_read_local_oob_data_reply_complete(struct hci_dev *hdev, u8 *hash,
u8 *randomizer, u8 status);
int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status);
+int mgmt_set_broadcaster_complete(struct hci_dev *hdev, bool changed,
+ u8 status);
int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name,
u8 ssp, u8 *eir, u16 eir_len);
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index bbb4b4a..bd64816 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -92,6 +92,7 @@ struct mgmt_rp_read_index_list {
#define MGMT_SETTING_BREDR 0x00000080
#define MGMT_SETTING_HS 0x00000100
#define MGMT_SETTING_LE 0x00000200
+#define MGMT_SETTING_BROADCASTER 0x00000400
#define MGMT_OP_READ_INFO 0x0004
#define MGMT_READ_INFO_SIZE 0
@@ -365,6 +366,8 @@ struct mgmt_cp_unset_controller_data {
} __packed;
#define MGMT_UNSET_CONTROLLER_DATA_SIZE 1
+#define MGMT_OP_SET_BROADCASTER 0x002B
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 8f84f71..46f76d6 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1204,6 +1204,7 @@ static void hci_cc_read_local_oob_data_reply(struct hci_dev *hdev,
static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
{
__u8 *sent, status = *((__u8 *) skb->data);
+ __u8 enable;
BT_DBG("%s status 0x%2.2x", hdev->name, status);
@@ -1211,13 +1212,30 @@ static void hci_cc_le_set_adv_enable(struct hci_dev *hdev, struct sk_buff *skb)
if (!sent)
return;
+ enable = *sent;
+
hci_dev_lock(hdev);
- if (!status) {
- if (*sent)
- set_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
- else
- clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+ if (hdev->le_adv_req_reason == LE_ADV_REQ_REASON_BROADCASTER) {
+ bool changed = false;
+ if (enable) {
+ if (!test_and_set_bit(HCI_BROADCASTER,
+ &hdev->dev_flags))
+ changed = true;
+ } else {
+ if (test_and_clear_bit(HCI_BROADCASTER,
+ &hdev->dev_flags))
+ changed = true;
+ }
+ if (!test_bit(HCI_INIT, &hdev->flags))
+ mgmt_set_broadcaster_complete(hdev, changed, status);
+ } else {
+ if (!status) {
+ if (enable)
+ set_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+ else
+ clear_bit(HCI_LE_PERIPHERAL, &hdev->dev_flags);
+ }
}
hci_dev_unlock(hdev);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 0aa96bb..608e81af 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -392,8 +392,10 @@ static u32 get_supported_settings(struct hci_dev *hdev)
if (enable_hs)
settings |= MGMT_SETTING_HS;
- if (lmp_le_capable(hdev))
+ if (lmp_le_capable(hdev)) {
settings |= MGMT_SETTING_LE;
+ settings |= MGMT_SETTING_BROADCASTER;
+ }
return settings;
}
@@ -420,6 +422,9 @@ static u32 get_current_settings(struct hci_dev *hdev)
if (test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
settings |= MGMT_SETTING_LE;
+ if (test_bit(HCI_BROADCASTER, &hdev->dev_flags))
+ settings |= MGMT_SETTING_BROADCASTER;
+
if (test_bit(HCI_LINK_SECURITY, &hdev->dev_flags))
settings |= MGMT_SETTING_LINK_SECURITY;
@@ -2762,6 +2767,64 @@ static int unset_controller_data(struct sock *sk, struct hci_dev *hdev,
NULL, 0);
}
+static int set_broadcaster_le(struct sock *sk, struct hci_dev *hdev, u8 enable)
+{
+ struct pending_cmd *cmd;
+ int err;
+
+ BT_DBG("%s enable:%i", hdev->name, enable);
+
+ hci_dev_lock(hdev);
+
+ if (!hdev_is_powered(hdev)) {
+ err = cmd_status(sk, hdev->id, MGMT_OP_SET_BROADCASTER,
+ MGMT_STATUS_NOT_POWERED);
+ goto unlock;
+ }
+
+ if (enable == test_bit(HCI_BROADCASTER, &hdev->dev_flags)) {
+ err = send_settings_rsp(sk, MGMT_OP_SET_BROADCASTER, hdev);
+ goto unlock;
+ }
+
+ if (mgmt_pending_find(MGMT_OP_SET_BROADCASTER, hdev)) {
+ err = cmd_status(sk, hdev->id, MGMT_OP_SET_BROADCASTER,
+ MGMT_STATUS_BUSY);
+ goto unlock;
+ }
+
+ cmd = mgmt_pending_add(sk, MGMT_OP_SET_BROADCASTER, hdev, NULL, 0);
+ if (!cmd) {
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ hdev->le_adv_req_reason = LE_ADV_REQ_REASON_BROADCASTER;
+
+ err = hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_ENABLE, sizeof(enable),
+ &enable);
+ if (err < 0)
+ mgmt_pending_remove(cmd);
+
+unlock:
+ hci_dev_unlock(hdev);
+ return err;
+}
+
+static int set_broadcaster(struct sock *sk, struct hci_dev *hdev, void *data,
+ u16 len)
+{
+ struct mgmt_mode *cp = data;
+
+ BT_DBG("%s val:%i", hdev->name, cp->val);
+
+ if (!test_bit(HCI_LE_ENABLED, &hdev->dev_flags))
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_BROADCASTER,
+ MGMT_STATUS_NOT_SUPPORTED);
+
+ return set_broadcaster_le(sk, hdev, cp->val);
+}
+
static const struct mgmt_handler {
int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
u16 data_len);
@@ -2811,6 +2874,7 @@ static const struct mgmt_handler {
{ set_device_id, false, MGMT_SET_DEVICE_ID_SIZE },
{ set_controller_data, true, MGMT_SET_CONTROLLER_DATA_SIZE },
{ unset_controller_data, false, MGMT_UNSET_CONTROLLER_DATA_SIZE },
+ { set_broadcaster, false, MGMT_SETTING_SIZE },
};
@@ -3667,6 +3731,33 @@ int mgmt_le_enable_complete(struct hci_dev *hdev, u8 enable, u8 status)
return err;
}
+int mgmt_set_broadcaster_complete(struct hci_dev *hdev, bool changed, u8 status)
+{
+ struct pending_cmd *cmd;
+ struct cmd_lookup match = { NULL, hdev };
+ int err = 0;
+
+ cmd = mgmt_pending_find(MGMT_OP_SET_BROADCASTER, hdev);
+ if (!cmd)
+ return -ENOENT;
+
+ if (status) {
+ u8 mgmt_err = mgmt_status(status);
+ cmd_status_rsp(cmd, &mgmt_err);
+ return err;
+ }
+
+ settings_rsp(cmd, &match);
+
+ if (changed)
+ err = new_settings(hdev, match.sk);
+
+ if (match.sk)
+ sock_put(match.sk);
+
+ return err;
+}
+
int mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type,
u8 addr_type, u8 *dev_class, s8 rssi, u8 cfm_name, u8
ssp, u8 *eir, u16 eir_len)
--
1.8.0.2
Unset controller data allows user to remove some data previously set to be
broadcasted via set controller data MGMT command.
Signed-off-by: Jefferson Delfes <[email protected]>
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
include/net/bluetooth/hci_core.h | 1 +
include/net/bluetooth/mgmt.h | 6 ++++++
net/bluetooth/hci_core.c | 19 +++++++++++++++++++
net/bluetooth/mgmt.c | 24 ++++++++++++++++++++++++
4 files changed, 50 insertions(+)
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 49a9ead..cf8d125 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -765,6 +765,7 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
int hci_broadcast_data_add(struct hci_dev *hdev, u8 flags, u8 type, u8 length,
u8 *data);
+int hci_broadcast_data_remove(struct hci_dev *hdev, u8 type);
int hci_broadcast_data_clear(struct hci_dev *hdev);
#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index f99e0a8..bbb4b4a 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -359,6 +359,12 @@ struct mgmt_cp_set_controller_data {
} __packed;
#define MGMT_SET_CONTROLLER_DATA_SIZE 3
+#define MGMT_OP_UNSET_CONTROLLER_DATA 0x002A
+struct mgmt_cp_unset_controller_data {
+ __u8 type;
+} __packed;
+#define MGMT_UNSET_CONTROLLER_DATA_SIZE 1
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 6d6ee0c..d015e1f 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1524,6 +1524,25 @@ int hci_broadcast_data_add(struct hci_dev *hdev, u8 flags, u8 type, u8 length,
return 0;
}
+int hci_broadcast_data_remove(struct hci_dev *hdev, u8 type)
+{
+ struct broadcast_data *match, *n;
+ int matches = 0;
+
+ list_for_each_entry_safe(match, n, &hdev->broadcast_data, list) {
+ if (type != match->type)
+ continue;
+
+ list_del(&match->list);
+ hdev->broadcast_data_len -= sizeof(match->length) +
+ sizeof(match->type) + match->length;
+ kfree(match);
+ matches++;
+ }
+
+ return matches;
+}
+
int hci_broadcast_data_clear(struct hci_dev *hdev)
{
struct broadcast_data *b_data, *n;
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 4623cf0..0aa96bb 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2739,6 +2739,29 @@ static int set_controller_data(struct sock *sk, struct hci_dev *hdev,
0);
}
+static int unset_controller_data(struct sock *sk, struct hci_dev *hdev,
+ void *data, u16 len)
+{
+ struct mgmt_cp_unset_controller_data *cp = data;
+
+ BT_DBG("%s type:0x%02x", hdev->name, cp->type);
+
+ hci_dev_lock(hdev);
+
+ if (!hdev_is_powered(hdev)) {
+ hci_dev_unlock(hdev);
+ return cmd_status(sk, hdev->id, MGMT_OP_UNSET_CONTROLLER_DATA,
+ MGMT_STATUS_NOT_POWERED);
+ }
+
+ hci_broadcast_data_remove(hdev, cp->type);
+
+ hci_dev_unlock(hdev);
+
+ return cmd_complete(sk, hdev->id, MGMT_OP_UNSET_CONTROLLER_DATA, 0,
+ NULL, 0);
+}
+
static const struct mgmt_handler {
int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
u16 data_len);
@@ -2787,6 +2810,7 @@ static const struct mgmt_handler {
{ unblock_device, false, MGMT_UNBLOCK_DEVICE_SIZE },
{ set_device_id, false, MGMT_SET_DEVICE_ID_SIZE },
{ set_controller_data, true, MGMT_SET_CONTROLLER_DATA_SIZE },
+ { unset_controller_data, false, MGMT_UNSET_CONTROLLER_DATA_SIZE },
};
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
Set controller data allows user to set broadcast advertising data. The available
data types are 'service data' and 'manufacturer specific data'.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
Signed-off-by: Jefferson Delfes <[email protected]>
---
include/net/bluetooth/hci.h | 3 +++
include/net/bluetooth/hci_core.h | 15 +++++++++++++++
include/net/bluetooth/mgmt.h | 9 +++++++++
net/bluetooth/hci_core.c | 36 ++++++++++++++++++++++++++++++++++++
net/bluetooth/mgmt.c | 39 +++++++++++++++++++++++++++++++++++++++
5 files changed, 102 insertions(+)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index e89311d..a89ff01 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -337,6 +337,9 @@ enum {
#define EIR_SSP_HASH_C 0x0E /* Simple Pairing Hash C */
#define EIR_SSP_RAND_R 0x0F /* Simple Pairing Randomizer R */
#define EIR_DEVICE_ID 0x10 /* device ID */
+/* Advertising field types */
+#define ADV_SERVICE_DATA 0x16 /* Service Data */
+#define ADV_MANUFACTURER_DATA 0xFF /* Manufacturer Specific Data */
/* Low Energy Advertising Flags */
#define LE_AD_LIMITED 0x01 /* Limited Discoverable */
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 014a2ea..49a9ead 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -123,6 +123,14 @@ struct le_scan_params {
int timeout;
};
+struct broadcast_data {
+ struct list_head list;
+ u8 flags;
+ u8 type;
+ u8 length;
+ u8 data[0];
+};
+
#define HCI_MAX_SHORT_NAME_LENGTH 10
struct amp_assoc {
@@ -282,6 +290,9 @@ struct hci_dev {
__u8 adv_data[HCI_MAX_AD_LENGTH];
__u8 adv_data_len;
+ struct list_head broadcast_data;
+ __u16 broadcast_data_len;
+
int (*open)(struct hci_dev *hdev);
int (*close)(struct hci_dev *hdev);
int (*flush)(struct hci_dev *hdev);
@@ -752,6 +763,10 @@ void hci_conn_init_sysfs(struct hci_conn *conn);
void hci_conn_add_sysfs(struct hci_conn *conn);
void hci_conn_del_sysfs(struct hci_conn *conn);
+int hci_broadcast_data_add(struct hci_dev *hdev, u8 flags, u8 type, u8 length,
+ u8 *data);
+int hci_broadcast_data_clear(struct hci_dev *hdev);
+
#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev))
/* ----- LMP capabilities ----- */
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 22980a7..f99e0a8 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -350,6 +350,15 @@ struct mgmt_cp_set_device_id {
} __packed;
#define MGMT_SET_DEVICE_ID_SIZE 8
+#define MGMT_OP_SET_CONTROLLER_DATA 0x0029
+struct mgmt_cp_set_controller_data {
+ __u8 flags;
+ __u8 type;
+ __u8 length;
+ __u8 data[0];
+} __packed;
+#define MGMT_SET_CONTROLLER_DATA_SIZE 3
+
#define MGMT_EV_CMD_COMPLETE 0x0001
struct mgmt_ev_cmd_complete {
__le16 opcode;
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index ec7d3a7..6d6ee0c 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1504,6 +1504,40 @@ int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 *hash,
return 0;
}
+int hci_broadcast_data_add(struct hci_dev *hdev, u8 flags, u8 type, u8 length,
+ u8 *data)
+{
+ struct broadcast_data *b_data;
+
+ b_data = kmalloc(sizeof(*b_data) + length, GFP_KERNEL);
+ if (!b_data)
+ return -ENOMEM;
+
+ b_data->flags = flags;
+ b_data->type = type;
+ b_data->length = length;
+ memcpy(b_data->data, data, length);
+
+ list_add(&b_data->list, &hdev->broadcast_data);
+ hdev->broadcast_data_len += sizeof(length) + sizeof(type) + length;
+
+ return 0;
+}
+
+int hci_broadcast_data_clear(struct hci_dev *hdev)
+{
+ struct broadcast_data *b_data, *n;
+
+ list_for_each_entry_safe(b_data, n, &hdev->broadcast_data, list) {
+ list_del(&b_data->list);
+ kfree(b_data);
+ }
+
+ hdev->broadcast_data_len = 0;
+
+ return 0;
+}
+
struct bdaddr_list *hci_blacklist_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr)
{
struct bdaddr_list *b;
@@ -1721,6 +1755,7 @@ struct hci_dev *hci_alloc_dev(void)
INIT_LIST_HEAD(&hdev->long_term_keys);
INIT_LIST_HEAD(&hdev->remote_oob_data);
INIT_LIST_HEAD(&hdev->conn_hash.list);
+ INIT_LIST_HEAD(&hdev->broadcast_data);
INIT_WORK(&hdev->rx_work, hci_rx_work);
INIT_WORK(&hdev->cmd_work, hci_cmd_work);
@@ -1887,6 +1922,7 @@ void hci_unregister_dev(struct hci_dev *hdev)
hci_link_keys_clear(hdev);
hci_smp_ltks_clear(hdev);
hci_remote_oob_data_clear(hdev);
+ hci_broadcast_data_clear(hdev);
hci_dev_unlock(hdev);
hci_dev_put(hdev);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 5d0ef75..4623cf0 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2701,6 +2701,44 @@ static int load_long_term_keys(struct sock *sk, struct hci_dev *hdev,
return 0;
}
+static int set_controller_data(struct sock *sk, struct hci_dev *hdev,
+ void *data, u16 len)
+{
+ struct mgmt_cp_set_controller_data *cp = data;
+ u8 room;
+
+ BT_DBG("%s", hdev->name);
+
+ if (cp->type != ADV_SERVICE_DATA && cp->type != ADV_MANUFACTURER_DATA)
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_CONTROLLER_DATA,
+ MGMT_STATUS_INVALID_PARAMS);
+
+ hci_dev_lock(hdev);
+
+ if (!hdev_is_powered(hdev)) {
+ hci_dev_unlock(hdev);
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_CONTROLLER_DATA,
+ MGMT_STATUS_NOT_POWERED);
+ }
+
+ room = HCI_MAX_AD_LENGTH - hdev->broadcast_data_len;
+ if (sizeof(cp->length) + sizeof(cp->type) + cp->length > room) {
+ hci_dev_unlock(hdev);
+ return cmd_status(sk, hdev->id, MGMT_OP_SET_CONTROLLER_DATA,
+ MGMT_STATUS_NO_RESOURCES);
+ }
+
+ BT_DBG("flags:0x%02x length:%i type:0x%02x", cp->flags, cp->length,
+ cp->type);
+
+ hci_broadcast_data_add(hdev, cp->flags, cp->type, cp->length, cp->data);
+
+ hci_dev_unlock(hdev);
+
+ return cmd_complete(sk, hdev->id, MGMT_OP_SET_CONTROLLER_DATA, 0, NULL,
+ 0);
+}
+
static const struct mgmt_handler {
int (*func) (struct sock *sk, struct hci_dev *hdev, void *data,
u16 data_len);
@@ -2748,6 +2786,7 @@ static const struct mgmt_handler {
{ block_device, false, MGMT_BLOCK_DEVICE_SIZE },
{ unblock_device, false, MGMT_UNBLOCK_DEVICE_SIZE },
{ set_device_id, false, MGMT_SET_DEVICE_ID_SIZE },
+ { set_controller_data, true, MGMT_SET_CONTROLLER_DATA_SIZE },
};
--
1.8.0.2
From: Aloisio Almeida Jr <[email protected]>
To enable broadcasting we need to set up the advertising parameters. As these
parameters are constant (only broadcaster is using until now), they are set on LE
setup.
This patch makes the advertising non-connectable as default. To make connectable
advertising using 'hciconfig leadv' command, you must change these parameters
first.
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
net/bluetooth/hci_event.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 705078a..8f84f71 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -606,11 +606,22 @@ static void bredr_setup(struct hci_dev *hdev)
static void le_setup(struct hci_dev *hdev)
{
+ struct hci_cp_le_set_adv_params params;
+
/* Read LE Buffer Size */
hci_send_cmd(hdev, HCI_OP_LE_READ_BUFFER_SIZE, 0, NULL);
/* Read LE Advertising Channel TX Power */
hci_send_cmd(hdev, HCI_OP_LE_READ_ADV_TX_POWER, 0, NULL);
+
+ /* Set ADV params */
+ memset(¶ms, 0, sizeof(params));
+ params.interval_min = __constant_cpu_to_le16(0x0800);
+ params.interval_max = __constant_cpu_to_le16(0x0800);
+ params.type = ADV_NONCONN_IND;
+ params.own_address_type = ADDR_LE_DEV_PUBLIC;
+ params.channel_map = ADV_USE_ALL_CHANNELS;
+ hci_send_cmd(hdev, HCI_OP_LE_SET_ADV_PARAMS, sizeof(params), ¶ms);
}
static void hci_setup(struct hci_dev *hdev)
@@ -1359,6 +1370,15 @@ static void hci_cc_write_remote_amp_assoc(struct hci_dev *hdev,
amp_write_rem_assoc_continue(hdev, rp->phy_handle);
}
+static void hci_cc_le_set_adv_params(struct hci_dev *hdev, struct sk_buff *skb)
+{
+ __u8 status = *((__u8 *) skb->data);
+
+ BT_DBG("%s status 0x%2.2x", hdev->name, status);
+
+ hci_req_complete(hdev, HCI_OP_LE_SET_ADV_PARAMS, status);
+}
+
static void hci_cs_inquiry(struct hci_dev *hdev, __u8 status)
{
BT_DBG("%s status 0x%2.2x", hdev->name, status);
@@ -2680,6 +2700,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb)
hci_cc_write_remote_amp_assoc(hdev, skb);
break;
+ case HCI_OP_LE_SET_ADV_PARAMS:
+ hci_cc_le_set_adv_params(hdev, skb);
+ break;
+
default:
BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode);
break;
--
1.8.0.2
Add command to set advertising parameters before enable it.
Signed-off-by: Jefferson Delfes <[email protected]>
Signed-off-by: Aloisio Almeida Jr <[email protected]>
---
include/net/bluetooth/hci.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 45eee08..e89311d 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -959,6 +959,20 @@ struct hci_cp_le_set_adv_data {
#define HCI_OP_LE_SET_ADV_ENABLE 0x200a
+#define ADV_USE_ALL_CHANNELS 0x07
+
+#define HCI_OP_LE_SET_ADV_PARAMS 0x2006
+struct hci_cp_le_set_adv_params {
+ __le16 interval_min;
+ __le16 interval_max;
+ __u8 type;
+ __u8 own_address_type;
+ __u8 direct_address_type;
+ __u8 direct_address[6];
+ __u8 channel_map;
+ __u8 filter_policy;
+} __packed;
+
#define HCI_OP_LE_SET_SCAN_PARAM 0x200b
struct hci_cp_le_set_scan_param {
__u8 type;
--
1.8.0.2
bump
On Fri, Dec 14, 2012 at 3:51 PM, Jefferson Delfes
<[email protected]> wrote:
> This patch series adds broadcaster and observer functionality.
>
> For the userspace, we are updating our branch and we will send it in s few
> days.
>
> Aloisio Almeida Jr (10):
> Bluetooth: Set advertising parameters on LE setup
> Bluetooth: Add set controller data MGMT command
> Bluetooth: Add set broadcaster MGMT command
> Bluetooth: Advertise controller data in broadcaster mode
> Bluetooth: Stop to acquire hdev lock inside hci_update_ad
> Bluetooth: Enable on-the-fly update of broadcast data
> Bluetooth: Enable support for broadcaster mode when powered off.
> Bluetooth: Refactor le scan helpers to enable observer support
> Bluetooth: Add set observer MGMT command
> Bluetooth: Enable support for observer mode when powered off.
>
> Jefferson Delfes (2):
> Bluetooth: Add HCI command to set advertising parameters
> Bluetooth: Add unset controller data MGMT command
>
> include/net/bluetooth/hci.h | 19 +++
> include/net/bluetooth/hci_core.h | 42 ++++-
> include/net/bluetooth/mgmt.h | 21 +++
> net/bluetooth/hci_core.c | 183 ++++++++++++++++-----
> net/bluetooth/hci_event.c | 121 +++++++++-----
> net/bluetooth/mgmt.c | 335 +++++++++++++++++++++++++++++++++++++--
> 6 files changed, 628 insertions(+), 93 deletions(-)
>
> --
> 1.8.0.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html