linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 09/15] Bluetooth: Merge boolean members of struct hci_conn into flags
Date: Wed, 18 Jan 2012 20:51:51 +0200	[thread overview]
Message-ID: <1326912717-6347-10-git-send-email-johan.hedberg@gmail.com> (raw)
In-Reply-To: <1326912717-6347-1-git-send-email-johan.hedberg@gmail.com>

From: Johan Hedberg <johan.hedberg@intel.com>

Now that the flags member of struct hci_conn is supposed to accommodate
any boolean type values we can easily merge all boolean members into it.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/hci_core.h |    6 +++---
 net/bluetooth/hci_conn.c         |   15 +++++++++------
 net/bluetooth/hci_event.c        |   21 +++++++++++++--------
 3 files changed, 25 insertions(+), 17 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index c8ae176..5f6cb35 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -286,7 +286,6 @@ struct hci_conn {
 	__u8		attempt;
 	__u8		dev_class[3];
 	__u8		features[8];
-	__u8		ssp_mode;
 	__u16		interval;
 	__u16		pkt_type;
 	__u16		link_policy;
@@ -298,12 +297,10 @@ struct hci_conn {
 	__u8		pin_length;
 	__u8		enc_key_size;
 	__u8		io_capability;
-	__u8		power_save;
 	__u16		disc_timeout;
 	unsigned long	flags;
 
 	__u8		remote_cap;
-	__u8		remote_oob;
 	__u8		remote_auth;
 
 	unsigned int	sent;
@@ -409,6 +406,9 @@ enum {
 	HCI_CONN_MODE_CHANGE_PEND,
 	HCI_CONN_SCO_SETUP_PEND,
 	HCI_CONN_LE_SMP_PEND,
+	HCI_CONN_SSP_SUPPORT,
+	HCI_CONN_POWER_SAVE,
+	HCI_CONN_REMOTE_OOB,
 };
 
 static inline void hci_conn_hash_init(struct hci_dev *hdev)
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index 8a4678a..566254f 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -105,7 +105,8 @@ void hci_acl_connect(struct hci_conn *conn)
 		}
 
 		memcpy(conn->dev_class, ie->data.dev_class, 3);
-		conn->ssp_mode = ie->data.ssp_mode;
+		if (ie->data.ssp_mode > 0)
+			set_bit(HCI_CONN_SSP_SUPPORT, &conn->flags);
 	}
 
 	cp.pkt_type = cpu_to_le16(conn->pkt_type);
@@ -386,7 +387,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst)
 	conn->remote_auth = 0xff;
 	conn->key_type = 0xff;
 
-	conn->power_save = 1;
+	set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
 	conn->disc_timeout = HCI_DISCONN_TIMEOUT;
 
 	switch (type) {
@@ -586,7 +587,7 @@ struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *dst, __u8
 
 	if (acl->state == BT_CONNECTED &&
 			(sco->state == BT_OPEN || sco->state == BT_CLOSED)) {
-		acl->power_save = 1;
+		set_bit(HCI_CONN_POWER_SAVE, &acl->flags);
 		hci_conn_enter_active_mode(acl, BT_POWER_FORCE_ACTIVE_ON);
 
 		if (test_bit(HCI_CONN_MODE_CHANGE_PEND, &acl->flags)) {
@@ -607,7 +608,8 @@ int hci_conn_check_link_mode(struct hci_conn *conn)
 {
 	BT_DBG("conn %p", conn);
 
-	if (conn->ssp_mode > 0 && conn->hdev->ssp_mode > 0 &&
+	if (test_bit(HCI_CONN_SSP_SUPPORT, &conn->flags) &&
+					conn->hdev->ssp_mode > 0 &&
 					!(conn->link_mode & HCI_LM_ENCRYPT))
 		return 0;
 
@@ -671,7 +673,8 @@ int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type)
 	/* For non 2.1 devices and low security level we don't need the link
 	   key. */
 	if (sec_level == BT_SECURITY_LOW &&
-				(!conn->ssp_mode || !conn->hdev->ssp_mode))
+			(!test_bit(HCI_CONN_SSP_SUPPORT, &conn->flags) ||
+							!conn->hdev->ssp_mode))
 		return 1;
 
 	/* For other security levels we need the link key. */
@@ -778,7 +781,7 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active)
 	if (conn->mode != HCI_CM_SNIFF)
 		goto timer;
 
-	if (!conn->power_save && !force_active)
+	if (!test_bit(HCI_CONN_POWER_SAVE, &conn->flags) && !force_active)
 		goto timer;
 
 	if (!test_and_set_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) {
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 373ae73..e592ddc 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -1264,7 +1264,8 @@ static int hci_outgoing_auth_needed(struct hci_dev *hdev,
 
 	/* Only request authentication for SSP connections or non-SSP
 	 * devices with sec_level HIGH or if MITM protection is requested */
-	if (!(hdev->ssp_mode > 0 && conn->ssp_mode > 0) &&
+	if (!(hdev->ssp_mode > 0 &&
+			test_bit(HCI_CONN_SSP_SUPPORT, &conn->flags)) &&
 				conn->pending_sec_level != BT_SECURITY_HIGH &&
 				!(conn->auth_type & 0x01))
 		return 0;
@@ -1816,7 +1817,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
 		goto unlock;
 
 	if (!ev->status) {
-		if (!(conn->ssp_mode > 0 && hdev->ssp_mode > 0) &&
+		if (!(test_bit(HCI_CONN_SSP_SUPPORT, &conn->flags) &&
+							hdev->ssp_mode > 0) &&
 				test_bit(HCI_CONN_REAUTH_PEND,	&conn->flags)) {
 			BT_INFO("re-auth of legacy device is not possible.");
 		} else {
@@ -1831,7 +1833,8 @@ static inline void hci_auth_complete_evt(struct hci_dev *hdev, struct sk_buff *s
 	clear_bit(HCI_CONN_REAUTH_PEND, &conn->flags);
 
 	if (conn->state == BT_CONFIG) {
-		if (!ev->status && hdev->ssp_mode > 0 && conn->ssp_mode > 0) {
+		if (!ev->status && hdev->ssp_mode > 0 &&
+				test_bit(HCI_CONN_SSP_SUPPORT, &conn->flags)) {
 			struct hci_cp_set_conn_encrypt cp;
 			cp.handle  = ev->handle;
 			cp.encrypt = 0x01;
@@ -2476,9 +2479,9 @@ static inline void hci_mode_change_evt(struct hci_dev *hdev, struct sk_buff *skb
 
 		if (!test_and_clear_bit(HCI_CONN_MODE_CHANGE_PEND, &conn->flags)) {
 			if (conn->mode == HCI_CM_ACTIVE)
-				conn->power_save = 1;
+				set_bit(HCI_CONN_POWER_SAVE, &conn->flags);
 			else
-				conn->power_save = 0;
+				clear_bit(HCI_CONN_POWER_SAVE, &conn->flags);
 		}
 
 		if (test_and_clear_bit(HCI_CONN_SCO_SETUP_PEND, &conn->flags))
@@ -2751,7 +2754,8 @@ static inline void hci_remote_ext_features_evt(struct hci_dev *hdev, struct sk_b
 		if (ie)
 			ie->data.ssp_mode = (ev->features[0] & 0x01);
 
-		conn->ssp_mode = (ev->features[0] & 0x01);
+		if (ev->features[0] & 0x01)
+			set_bit(HCI_CONN_SSP_SUPPORT, &conn->flags);
 	}
 
 	if (conn->state != BT_CONFIG)
@@ -2930,7 +2934,7 @@ static inline void hci_io_capa_request_evt(struct hci_dev *hdev, struct sk_buff
 		conn->auth_type = hci_get_auth_req(conn);
 		cp.authentication = conn->auth_type;
 
-		if ((conn->out == 0x01 || conn->remote_oob == 0x01) &&
+		if ((conn->out || test_bit(HCI_CONN_REMOTE_OOB, &conn->flags)) &&
 				hci_find_remote_oob_data(hdev, &conn->dst))
 			cp.oob_data = 0x01;
 		else
@@ -2966,8 +2970,9 @@ static inline void hci_io_capa_reply_evt(struct hci_dev *hdev, struct sk_buff *s
 		goto unlock;
 
 	conn->remote_cap = ev->capability;
-	conn->remote_oob = ev->oob_data;
 	conn->remote_auth = ev->authentication;
+	if (ev->oob_data)
+		set_bit(HCI_CONN_REMOTE_OOB, &conn->flags);
 
 unlock:
 	hci_dev_unlock(hdev);
-- 
1.7.8.3


  parent reply	other threads:[~2012-01-18 18:51 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-18 18:51 [PATCH 0/15] Bluetooth: Update to latest mgmt API Johan Hedberg
2012-01-18 18:51 ` [PATCH 01/15] Bluetooth: Fix clearing persistent flags Johan Hedberg
2012-01-18 19:02   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 02/15] Bluetooth: Rename mgmt connected events to match user space Johan Hedberg
2012-01-18 19:03   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 03/15] Bluetooth: Add eir_len parameter to mgmt_ev_device_found Johan Hedberg
2012-01-18 19:04   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 04/15] Bluetooth: Rename eir_has_complete_name to eir_has_data_type Johan Hedberg
2012-01-18 19:05   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 05/15] Bluetooth: Add missing EIR defines to hci.h Johan Hedberg
2012-01-18 19:05   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 06/15] Bluetooth: Move eir_has_data_field to hci_core.h Johan Hedberg
2012-01-18 19:06   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 07/15] Bluetooth: Merge device class into the EIR data in mgmt_ev_device_found Johan Hedberg
2012-01-18 19:08   ` Marcel Holtmann
2012-01-18 19:18   ` Anderson Lizardo
2012-01-18 20:29     ` Johan Hedberg
2012-01-18 20:40       ` Anderson Lizardo
2012-01-18 20:58         ` Johan Hedberg
2012-01-19  9:26   ` Andrei Emeltchenko
2012-01-18 18:51 ` [PATCH 08/15] Bluetooth: Rename conn->pend to conn->flags Johan Hedberg
2012-01-18 19:12   ` Marcel Holtmann
2012-01-18 18:51 ` Johan Hedberg [this message]
2012-01-18 19:12   ` [PATCH 09/15] Bluetooth: Merge boolean members of struct hci_conn into flags Marcel Holtmann
2012-01-18 19:25     ` Johan Hedberg
2012-01-18 19:31       ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 10/15] Bluetooth: Add a convenience function to check for SSP enabled Johan Hedberg
2012-01-18 19:14   ` Marcel Holtmann
2012-01-19  9:30   ` Andrei Emeltchenko
2012-01-19  9:39     ` Johan Hedberg
2012-01-18 18:51 ` [PATCH 11/15] Bluetooth: Convert hdev->ssp_mode to a flag Johan Hedberg
2012-01-18 19:14   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 12/15] Bluetooth: Convert hdev->out to a bool type Johan Hedberg
2012-01-18 19:15   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 13/15] Bluetooth: Update device_connected and device_found events to latest API Johan Hedberg
2012-01-18 19:17   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 14/15] Bluetooth: Rename hdev->flags to hdev->compat_flags Johan Hedberg
2012-01-18 19:18   ` Marcel Holtmann
2012-01-18 18:51 ` [PATCH 15/15] Bluetooth: Rename hdev->dev_flags to hdev-flags Johan Hedberg

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=1326912717-6347-10-git-send-email-johan.hedberg@gmail.com \
    --to=johan.hedberg@gmail.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).