From patchwork Mon Jul 11 19:50:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 9224075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E134360890 for ; Mon, 11 Jul 2016 19:52:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D318E27D29 for ; Mon, 11 Jul 2016 19:52:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7E7227E15; Mon, 11 Jul 2016 19:52:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7059E27D29 for ; Mon, 11 Jul 2016 19:52:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752529AbcGKTwF (ORCPT ); Mon, 11 Jul 2016 15:52:05 -0400 Received: from metis.ext.4.pengutronix.de ([92.198.50.35]:59761 "EHLO metis.ext.4.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752524AbcGKTvT (ORCPT ); Mon, 11 Jul 2016 15:51:19 -0400 Received: from gallifrey.ext.pengutronix.de ([2001:67c:670:201:5054:ff:fe8d:eefb] helo=omega.localdomain) by metis.ext.pengutronix.de with esmtp (Exim 4.80) (envelope-from ) id 1bMhEc-00038F-3b; Mon, 11 Jul 2016 21:51:18 +0200 From: Alexander Aring To: linux-wpan@vger.kernel.org Cc: kernel@pengutronix.de, luiz.dentz@gmail.com, kaspar@schleiser.de, jukka.rissanen@linux.intel.com, linux-bluetooth@vger.kernel.org, Patrik.Flykt@linux.intel.com, Alexander Aring Subject: [RFC bluetooth-next 10/20] bluetooth: add hci dev notifier Date: Mon, 11 Jul 2016 21:50:34 +0200 Message-Id: <20160711195044.25343-11-aar@pengutronix.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160711195044.25343-1-aar@pengutronix.de> References: <20160711195044.25343-1-aar@pengutronix.de> X-SA-Exim-Connect-IP: 2001:67c:670:201:5054:ff:fe8d:eefb X-SA-Exim-Mail-From: aar@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-wpan@vger.kernel.org Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP I need to react at least somehow on a hci dev unregister event to clean all 6LoWPAN interfaces on it. This patch adds a notifier for non socket stuff. I also thought about to react somehow on "struct device" unregister but I didn't found any functionality for that. Signed-off-by: Alexander Aring --- include/net/bluetooth/hci_core.h | 4 ++++ net/bluetooth/hci_core.c | 22 ++++++++++++++++++++++ net/bluetooth/hci_sock.c | 2 ++ 3 files changed, 28 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index dc71473..a37027a 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -902,6 +902,10 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); void hci_le_conn_failed(struct hci_conn *conn, u8 status); +int register_hci_dev_notifier(struct notifier_block *nb); +void unregister_hci_dev_notifier(struct notifier_block *nb); +int call_hci_dev_notifiers(unsigned long val, struct hci_dev *hdev); + /* * hci_conn_get() and hci_conn_put() are used to control the life-time of an * "hci_conn" object. They do not guarantee that the hci_conn object is running, diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 98f6c37..a75e9e7 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -57,6 +57,28 @@ DEFINE_MUTEX(hci_cb_list_lock); /* HCI ID Numbering */ static DEFINE_IDA(hci_index_ida); +/* HCI device notifier list */ +static RAW_NOTIFIER_HEAD(hci_dev_chain); + +/* ---- HCI notifiers functions ---- */ + +int register_hci_dev_notifier(struct notifier_block *nb) +{ + return raw_notifier_chain_register(&hci_dev_chain, nb); +} +EXPORT_SYMBOL(register_hci_dev_notifier); + +void unregister_hci_dev_notifier(struct notifier_block *nb) +{ + raw_notifier_chain_unregister(&hci_dev_chain, nb); +} +EXPORT_SYMBOL(unregister_hci_dev_notifier); + +int call_hci_dev_notifiers(unsigned long val, struct hci_dev *hdev) +{ + return raw_notifier_call_chain(&hci_dev_chain, val, hdev); +} + /* ---- HCI debugfs entries ---- */ static ssize_t dut_mode_read(struct file *file, char __user *user_buf, diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c index 6ef8a01..290eb1e 100644 --- a/net/bluetooth/hci_sock.c +++ b/net/bluetooth/hci_sock.c @@ -529,6 +529,8 @@ void hci_sock_dev_event(struct hci_dev *hdev, int event) } read_unlock(&hci_sk_list.lock); } + + call_hci_dev_notifiers(event, hdev); } static struct hci_mgmt_chan *__hci_mgmt_chan_find(unsigned short channel)