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 9/9] Bluetooth: Implement secondary advertising on different PHYs
Date: Mon,  4 Dec 2017 13:37:53 +0530	[thread overview]
Message-ID: <1512374873-1956-10-git-send-email-jaganathx.kanakkassery@intel.com> (raw)
In-Reply-To: <1512374873-1956-1-git-send-email-jaganathx.kanakkassery@intel.com>

This patch adds support for advertising in primary and secondary
channel on different PHYs. User can add the phy preference in
the flag based on which phy type will be added in extended
advertising parameter would be set.

Signed-off-by: Jaganath Kanakkassery <jaganathx.kanakkassery@intel.com>
---
 include/net/bluetooth/hci.h  |  6 +++++-
 include/net/bluetooth/mgmt.h |  6 ++++++
 net/bluetooth/hci_request.c  | 18 +++++++++++++++---
 net/bluetooth/mgmt.c         | 18 ++++++++++++++++--
 4 files changed, 42 insertions(+), 6 deletions(-)

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 1337fbf..40a22e2 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -398,6 +398,8 @@ enum {
 #define HCI_LE_SLAVE_FEATURES		0x08
 #define HCI_LE_PING			0x10
 #define HCI_LE_DATA_LEN_EXT		0x20
+#define HCI_LE_PHY_2M			0x01
+#define HCI_LE_PHY_CODED		0x08
 #define HCI_LE_EXT_ADV			0x10
 #define HCI_LE_EXT_SCAN_POLICY		0x80
 
@@ -1507,7 +1509,9 @@ struct hci_cp_le_set_ext_scan_params {
         __u8	data[0];
 } __packed;
 
-#define LE_PHY_1M 0x01
+#define LE_PHY_1M 	0x01
+#define LE_PHY_2M 	0x02
+#define LE_PHY_CODED	0x03
 
 struct hci_cp_le_scan_phy_params {
         __u8	type;
diff --git a/include/net/bluetooth/mgmt.h b/include/net/bluetooth/mgmt.h
index 72a456b..f1055dd 100644
--- a/include/net/bluetooth/mgmt.h
+++ b/include/net/bluetooth/mgmt.h
@@ -561,6 +561,12 @@ struct mgmt_rp_add_advertising {
 #define MGMT_ADV_FLAG_TX_POWER		BIT(4)
 #define MGMT_ADV_FLAG_APPEARANCE	BIT(5)
 #define MGMT_ADV_FLAG_LOCAL_NAME	BIT(6)
+#define MGMT_ADV_FLAG_SEC_1M 		BIT(7)
+#define MGMT_ADV_FLAG_SEC_2M 		BIT(8)
+#define MGMT_ADV_FLAG_SEC_CODED 	BIT(9)
+
+#define MGMT_ADV_FLAG_SEC_MASK	(MGMT_ADV_FLAG_SEC_1M | MGMT_ADV_FLAG_SEC_2M | \
+				 MGMT_ADV_FLAG_SEC_CODED)
 
 #define MGMT_OP_REMOVE_ADVERTISING	0x003F
 struct mgmt_cp_remove_advertising {
diff --git a/net/bluetooth/hci_request.c b/net/bluetooth/hci_request.c
index 9d0a940..68c2f18 100644
--- a/net/bluetooth/hci_request.c
+++ b/net/bluetooth/hci_request.c
@@ -1590,7 +1590,8 @@ static void __hci_req_setup_ext_adv_instance(struct hci_request *req,
 		return;
 
 	secondary_adv = (adv_inst->adv_data_len > HCI_MAX_AD_LENGTH ||
-			 adv_inst->scan_rsp_len > HCI_MAX_AD_LENGTH);
+			 adv_inst->scan_rsp_len > HCI_MAX_AD_LENGTH ||
+			 flags & MGMT_ADV_FLAG_SEC_MASK);
 
 	if (connectable) {
 		if (secondary_adv)
@@ -1612,8 +1613,19 @@ static void __hci_req_setup_ext_adv_instance(struct hci_request *req,
 	cp.own_addr_type = own_addr_type;
 	cp.channel_map = hdev->le_adv_channel_map;
 	cp.tx_power = 127;
-	cp.primary_phy = LE_PHY_1M;
-	cp.secondary_phy = LE_PHY_1M;
+
+	if (flags & MGMT_ADV_FLAG_SEC_2M){
+		cp.primary_phy = LE_PHY_1M;
+		cp.secondary_phy = LE_PHY_2M;
+	} else if (flags & MGMT_ADV_FLAG_SEC_CODED) {
+		cp.primary_phy = LE_PHY_CODED;
+		cp.secondary_phy = LE_PHY_CODED;
+	} else {
+		/* In all other cases use 1M */
+		cp.primary_phy = LE_PHY_1M;
+		cp.secondary_phy = LE_PHY_1M;
+	}
+
 	cp.handle = instance;
 
 	hci_req_add(req, HCI_OP_LE_SET_EXT_ADV_PARAMS, sizeof(cp), &cp);
diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 120da46..68cf080 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -5996,6 +5996,16 @@ static u32 get_supported_adv_flags(struct hci_dev *hdev)
 	flags |= MGMT_ADV_FLAG_APPEARANCE;
 	flags |= MGMT_ADV_FLAG_LOCAL_NAME;
 
+	if (ext_adv_capable(hdev)) {
+		flags |= MGMT_ADV_FLAG_SEC_1M;
+
+		if (hdev->le_features[1] & HCI_LE_PHY_2M)
+			flags |= MGMT_ADV_FLAG_SEC_2M;
+
+		if (hdev->le_features[1] & HCI_LE_PHY_CODED)
+			flags |= MGMT_ADV_FLAG_SEC_CODED;
+	}
+
 	if (hdev->adv_tx_power != HCI_TX_POWER_INVALID)
 		flags |= MGMT_ADV_FLAG_TX_POWER;
 
@@ -6246,10 +6256,14 @@ static int add_advertising(struct sock *sk, struct hci_dev *hdev,
 	duration = __le16_to_cpu(cp->duration);
 
 	/* The current implementation only supports a subset of the specified
-	 * flags.
+	 * flags. Also need to check mutual exclusiveness of sec flags.
 	 */
 	supported_flags = get_supported_adv_flags(hdev);
-	if (flags & ~supported_flags)
+	if (flags & ~supported_flags ||
+	    ((flags & MGMT_ADV_FLAG_SEC_MASK) != 0 &&
+	     (flags & MGMT_ADV_FLAG_SEC_MASK) != MGMT_ADV_FLAG_SEC_1M &&
+	     (flags & MGMT_ADV_FLAG_SEC_MASK) != MGMT_ADV_FLAG_SEC_2M &&
+	     (flags & MGMT_ADV_FLAG_SEC_MASK) != MGMT_ADV_FLAG_SEC_CODED))
 		return mgmt_cmd_status(sk, hdev->id, MGMT_OP_ADD_ADVERTISING,
 				       MGMT_STATUS_INVALID_PARAMS);
 
-- 
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 ` [RFC 5/9] Bluetooth: Process Adv-Set Terminate event Jaganath Kanakkassery
2017-12-08  8:51   ` 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 ` Jaganath Kanakkassery [this message]
2017-12-08  9:00   ` [RFC 9/9] Bluetooth: Implement secondary advertising on different PHYs 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-10-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).