linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jaganath Kanakkassery <jaganath.k.os@gmail.com>
To: linux-bluetooth@vger.kernel.org
Cc: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
Subject: [RFC 5/9] Bluetooth: Process Adv-Set Terminate event
Date: Mon,  4 Dec 2017 13:37:49 +0530	[thread overview]
Message-ID: <1512374873-1956-6-git-send-email-jaganathx.kanakkassery@intel.com> (raw)
In-Reply-To: <1512374873-1956-1-git-send-email-jaganathx.kanakkassery@intel.com>

This patch enables and process Advertising Set Terminate event.
This event can come mainly in two scenarios - Connection and
timeout. In case of connection - adv instance state will be
changed to disabled and in timeout - adv instance will be removed.

Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
---
 include/net/bluetooth/hci.h |  8 ++++++
 net/bluetooth/hci_core.c    |  6 +++++
 net/bluetooth/hci_event.c   | 60 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 74 insertions(+)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 65d2124..2ee16f7 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -2115,6 +2115,14 @@ struct hci_ev_le_enh_conn_complete {
         __u8      clk_accurancy;
 } __packed;
 
+#define HCI_EV_LE_ADV_SET_TERM		0x12
+struct hci_ev_le_adv_set_term {
+	__u8  status;
+	__u8  handle;
+	__le16 conn_handle;
+	__u8  num_evts;
+} __packed;
+
 /* Internal events generated by Bluetooth stack */
 #define HCI_EV_STACK_INTERNAL	0xfd
 struct hci_ev_stack_internal {
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 6c22ed6..7f17325 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -689,6 +689,12 @@ static int hci_init3_req(struct hci_request *req, unsigned long opt)
 		if (hdev->commands[37] & 0x80)
 			events[1] |= 0x02;       /* LE Enhanced conn complete */
 
+		/* If the controller supports the LE Extended advertising
+		 *  enable the corresponding event.
+		 */
+		if (ext_adv_capable(hdev))
+			events[2] |= 0x02;        /* LE Adv Set Terminated */
+
 		hci_req_add(req, HCI_OP_LE_SET_EVENT_MASK, sizeof(events),
 			    events);
 
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 64873dd..8a118c1 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -4879,6 +4879,62 @@ static void hci_le_enh_conn_complete_evt(struct hci_dev *hdev,
 			     le16_to_cpu(ev->supervision_timeout));
 }
 
+static void hci_le_adv_set_terminated_evt(struct hci_dev *hdev,
+					  struct sk_buff *skb)
+{
+	struct hci_ev_le_adv_set_term *ev = (void *) skb->data;
+	struct adv_info *adv_instance = NULL;
+	int err;
+
+	hci_dev_lock(hdev);
+
+	if (ev->handle) {
+		adv_instance = hci_find_adv_instance(hdev, ev->handle);
+		if (!adv_instance)
+			goto unlock;
+	}
+
+	/* If this is because of connection */
+	if (!ev->status) {
+		if (!ev->handle)
+			hci_dev_clear_flag(hdev, HCI_LE_ADV);
+		else
+			clear_bit(ADV_INST_ENABLED, &adv_instance->state);
+	} else if (ev->handle) {
+		/* Remove the instance in all other cases */
+		err = hci_remove_adv_instance(hdev, ev->handle);
+		if (!err)
+			mgmt_advertising_removed(NULL, hdev, ev->handle);
+	}
+
+	/* If instance 0 was advertiing then others would be already disabled */
+	if (!ev->handle)
+		goto unlock;
+
+	/* Check state of other instances and modify flags accordingly */
+	list_for_each_entry(adv_instance, &hdev->adv_instances, list) {
+		if (test_bit(ADV_INST_ENABLED, &adv_instance->state)) {
+			if (!ev->status) {
+				struct hci_request req;
+
+				/* If it is a connection and another instance
+				 * is enabled then disable all, to be
+				 * alligned with the existing design
+				 */
+				hci_req_init(&req, hdev);
+				__hci_req_stop_ext_adv(&req, 0, true);
+				hci_req_run(&req, NULL);
+			}
+			goto unlock;
+		}
+	}
+
+	hci_dev_clear_flag(hdev, HCI_LE_ADV);
+
+unlock:
+	hci_dev_unlock(hdev);
+}
+
 static void hci_le_conn_update_complete_evt(struct hci_dev *hdev,
 					    struct sk_buff *skb)
 {
@@ -5492,6 +5548,10 @@ static void hci_le_meta_evt(struct hci_dev *hdev, struct sk_buff *skb)
 		hci_le_enh_conn_complete_evt(hdev, skb);
 		break;
 
+	case HCI_EV_LE_ADV_SET_TERM:
+		hci_le_adv_set_terminated_evt(hdev, skb);
+		break;
+
 	default:
 		break;
 	}
-- 
2.7.4


  parent reply	other threads:[~2017-12-04  8:07 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-04  8:07 [RFC 0/9] Extended Adv Jaganath Kanakkassery
2017-12-04  8:07 ` [RFC 1/9] Bluetooth: Read no of adv sets during init Jaganath Kanakkassery
2017-12-05 11:14   ` Luiz Augusto von Dentz
2017-12-07  7:57     ` Jaganath K
2017-12-07 10:42       ` Luiz Augusto von Dentz
2017-12-07 10:59         ` Jaganath K
2017-12-08  8:40     ` Marcel Holtmann
2017-12-08 11:57       ` Jaganath K
2017-12-08 18:34         ` Marcel Holtmann
2018-03-05 11:56           ` Jaganath K
2017-12-04  8:07 ` [RFC 2/9] Bluetooth: Impmlement extended adv enable Jaganath Kanakkassery
2017-12-04  8:07 ` [RFC 3/9] Bluetooth: Use Set ext adv/scan rsp data if controller supports Jaganath Kanakkassery
2017-12-08  8:46   ` Marcel Holtmann
2017-12-08 12:02     ` Jaganath K
2017-12-04  8:07 ` [RFC 4/9] Bluetooth: Implement disable and removal of adv instance Jaganath Kanakkassery
2017-12-04  8:07 ` Jaganath Kanakkassery [this message]
2017-12-08  8:51   ` [RFC 5/9] Bluetooth: Process Adv-Set Terminate event Marcel Holtmann
2017-12-04  8:07 ` [RFC 6/9] Bluetooth: Use ext adv for directed adv Jaganath Kanakkassery
2017-12-08  8:56   ` Marcel Holtmann
2017-12-04  8:07 ` [RFC 7/9] Bluetooth: Implement Set ADV set random address Jaganath Kanakkassery
2017-12-04  8:07 ` [RFC 8/9] Bluetooth: Handle incoming connection to an adv set Jaganath Kanakkassery
2017-12-04  8:07 ` [RFC 9/9] Bluetooth: Implement secondary advertising on different PHYs Jaganath Kanakkassery
2017-12-08  9:00   ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1512374873-1956-6-git-send-email-jaganathx.kanakkassery@intel.com \
    --to=jaganath.k.os@gmail.com \
    --cc=jaganathx.kanakkassery@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).