LOCAL / bluetooth: add hci event notification
authorBeomho Seo <beomho.seo@samsung.com>
Mon, 23 Feb 2015 08:00:31 +0000 (17:00 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Wed, 14 Dec 2016 04:41:18 +0000 (13:41 +0900)
For specific hci events, operations are needed. So this patch adds
event notification and its notifier registration.

Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
include/net/bluetooth/hci.h
include/net/bluetooth/hci_core.h
net/bluetooth/hci_core.c

index d95da83..54be456 100644 (file)
@@ -44,6 +44,7 @@
 #define HCI_DEV_DOWN                   4
 #define HCI_DEV_SUSPEND                        5
 #define HCI_DEV_RESUME                 6
+#define HCI_DEV_WRITE                  7
 
 /* HCI notify events */
 #define HCI_NOTIFY_CONN_ADD            1
index a056c2b..2c8dfdf 100644 (file)
@@ -1280,6 +1280,8 @@ static inline int hci_check_conn_params(u16 min, u16 max, u16 latency,
 
 int hci_register_cb(struct hci_cb *hcb);
 int hci_unregister_cb(struct hci_cb *hcb);
+int hci_register_notifier(struct notifier_block *nb);
+int hci_unregister_notifier(struct notifier_block *nb);
 
 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen,
                               const void *param, u32 timeout);
index c4802f3..71c44a6 100644 (file)
@@ -66,10 +66,25 @@ static DEFINE_IDA(hci_index_ida);
 #define hci_req_unlock(d)      mutex_unlock(&d->req_lock)
 
 /* ---- HCI notifications ---- */
+static ATOMIC_NOTIFIER_HEAD(hci_notifier);
+
+int hci_register_notifier(struct notifier_block *nb)
+{
+       return atomic_notifier_chain_register(&hci_notifier, nb);
+}
+
+int hci_unregister_notifier(struct notifier_block *nb)
+{
+       return atomic_notifier_chain_unregister(&hci_notifier, nb);
+}
 
 static void hci_notify(struct hci_dev *hdev, int event)
 {
        hci_sock_dev_event(hdev, event);
+
+       if (event == HCI_DEV_REG || event == HCI_DEV_UNREG
+                       || event == HCI_DEV_WRITE)
+               atomic_notifier_call_chain(&hci_notifier, event, hdev);
 }
 
 /* ---- HCI debugfs entries ---- */
@@ -3366,6 +3381,8 @@ static void hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
        /* Get rid of skb owner, prior to sending to the driver. */
        skb_orphan(skb);
 
+       hci_notify(hdev, HCI_DEV_WRITE);
+
        err = hdev->send(hdev, skb);
        if (err < 0) {
                BT_ERR("%s sending frame failed (%d)", hdev->name, err);