Commit 0602a8ad authored by Marcel Holtmann's avatar Marcel Holtmann

Bluetooth: Add support for Unconfigured Index Added events

When a controller is in unconfigured state it is currently hidden
from the management interface. This change now announces the new
controller with an Unconfigured Index Added event and allows clients
to easily detect the controller.
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 4a964404
...@@ -640,3 +640,5 @@ struct mgmt_ev_new_conn_param { ...@@ -640,3 +640,5 @@ struct mgmt_ev_new_conn_param {
__le16 latency; __le16 latency;
__le16 timeout; __le16 timeout;
} __packed; } __packed;
#define MGMT_EV_UNCONF_INDEX_ADDED 0x001d
...@@ -2806,13 +2806,17 @@ static void hci_power_on(struct work_struct *work) ...@@ -2806,13 +2806,17 @@ static void hci_power_on(struct work_struct *work)
if (test_and_clear_bit(HCI_SETUP, &hdev->dev_flags)) { if (test_and_clear_bit(HCI_SETUP, &hdev->dev_flags)) {
/* For unconfigured devices, set the HCI_RAW flag /* For unconfigured devices, set the HCI_RAW flag
* so that userspace can easily identify them. * so that userspace can easily identify them.
*
* If the device is fully configured and ready for
* operation, announce it via management interface.
*/ */
if (test_bit(HCI_UNCONFIGURED, &hdev->dev_flags)) if (test_bit(HCI_UNCONFIGURED, &hdev->dev_flags))
set_bit(HCI_RAW, &hdev->flags); set_bit(HCI_RAW, &hdev->flags);
else
/* For fully configured devices, this will send
* the Index Added event. For unconfigured devices,
* it will send Unconfigued Index Added event.
*
* Devices with HCI_QUIRK_RAW_DEVICE are ignored
* and no event will be send.
*/
mgmt_index_added(hdev); mgmt_index_added(hdev);
} }
} }
...@@ -4032,8 +4036,7 @@ void hci_unregister_dev(struct hci_dev *hdev) ...@@ -4032,8 +4036,7 @@ void hci_unregister_dev(struct hci_dev *hdev)
cancel_work_sync(&hdev->power_on); cancel_work_sync(&hdev->power_on);
if (!test_bit(HCI_INIT, &hdev->flags) && if (!test_bit(HCI_INIT, &hdev->flags) &&
!test_bit(HCI_SETUP, &hdev->dev_flags) && !test_bit(HCI_SETUP, &hdev->dev_flags)) {
!test_bit(HCI_UNCONFIGURED, &hdev->dev_flags)) {
hci_dev_lock(hdev); hci_dev_lock(hdev);
mgmt_index_removed(hdev); mgmt_index_removed(hdev);
hci_dev_unlock(hdev); hci_dev_unlock(hdev);
......
...@@ -453,7 +453,6 @@ static int hci_sock_release(struct socket *sock) ...@@ -453,7 +453,6 @@ static int hci_sock_release(struct socket *sock)
if (hdev) { if (hdev) {
if (hci_pi(sk)->channel == HCI_CHANNEL_USER) { if (hci_pi(sk)->channel == HCI_CHANNEL_USER) {
if (!test_bit(HCI_UNCONFIGURED, &hdev->dev_flags))
mgmt_index_added(hdev); mgmt_index_added(hdev);
clear_bit(HCI_USER_CHANNEL, &hdev->dev_flags); clear_bit(HCI_USER_CHANNEL, &hdev->dev_flags);
hci_dev_close(hdev->id); hci_dev_close(hdev->id);
...@@ -706,13 +705,11 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr, ...@@ -706,13 +705,11 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
goto done; goto done;
} }
if (!test_bit(HCI_UNCONFIGURED, &hdev->dev_flags))
mgmt_index_removed(hdev); mgmt_index_removed(hdev);
err = hci_dev_open(hdev->id); err = hci_dev_open(hdev->id);
if (err) { if (err) {
clear_bit(HCI_USER_CHANNEL, &hdev->dev_flags); clear_bit(HCI_USER_CHANNEL, &hdev->dev_flags);
if (!test_bit(HCI_UNCONFIGURED, &hdev->dev_flags))
mgmt_index_added(hdev); mgmt_index_added(hdev);
hci_dev_put(hdev); hci_dev_put(hdev);
goto done; goto done;
......
...@@ -118,6 +118,7 @@ static const u16 mgmt_events[] = { ...@@ -118,6 +118,7 @@ static const u16 mgmt_events[] = {
MGMT_EV_DEVICE_ADDED, MGMT_EV_DEVICE_ADDED,
MGMT_EV_DEVICE_REMOVED, MGMT_EV_DEVICE_REMOVED,
MGMT_EV_NEW_CONN_PARAM, MGMT_EV_NEW_CONN_PARAM,
MGMT_EV_UNCONF_INDEX_ADDED,
}; };
#define CACHE_TIMEOUT msecs_to_jiffies(2 * 1000) #define CACHE_TIMEOUT msecs_to_jiffies(2 * 1000)
...@@ -5373,6 +5374,12 @@ void mgmt_index_added(struct hci_dev *hdev) ...@@ -5373,6 +5374,12 @@ void mgmt_index_added(struct hci_dev *hdev)
if (hdev->dev_type != HCI_BREDR) if (hdev->dev_type != HCI_BREDR)
return; return;
if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
return;
if (test_bit(HCI_UNCONFIGURED, &hdev->dev_flags))
mgmt_event(MGMT_EV_UNCONF_INDEX_ADDED, hdev, NULL, 0, NULL);
else
mgmt_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, NULL); mgmt_event(MGMT_EV_INDEX_ADDED, hdev, NULL, 0, NULL);
} }
...@@ -5383,6 +5390,9 @@ void mgmt_index_removed(struct hci_dev *hdev) ...@@ -5383,6 +5390,9 @@ void mgmt_index_removed(struct hci_dev *hdev)
if (hdev->dev_type != HCI_BREDR) if (hdev->dev_type != HCI_BREDR)
return; return;
if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
return;
mgmt_pending_foreach(0, hdev, cmd_status_rsp, &status); mgmt_pending_foreach(0, hdev, cmd_status_rsp, &status);
mgmt_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, NULL); mgmt_event(MGMT_EV_INDEX_REMOVED, hdev, NULL, 0, NULL);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment