Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges
@ 2016-01-26 22:19 Johan Hedberg
  2016-01-26 22:19 ` [PATCH 2/3] Bluetooth: L2CAP: Fix auto-allocating LE PSM values Johan Hedberg
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Johan Hedberg @ 2016-01-26 22:19 UTC (permalink / raw)
  To: linux-bluetooth

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

Having proper defines makes the code a bit readable, it also avoids
duplicating hard-coded values since these are also needed when
auto-allocating PSM values (in a subsequent patch).

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/l2cap.h | 6 ++++++
 net/bluetooth/l2cap_sock.c    | 6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 52899291f401..5ee3c689c863 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -252,6 +252,12 @@ struct l2cap_conn_rsp {
 #define L2CAP_PSM_3DSP		0x0021
 #define L2CAP_PSM_IPSP		0x0023 /* 6LoWPAN */
 
+#define L2CAP_PSM_DYN_START	0x1001
+#define L2CAP_PSM_DYN_END	0xffff
+#define L2CAP_PSM_AUTO_END	0x10ff
+#define L2CAP_PSM_LE_DYN_START  0x0080
+#define L2CAP_PSM_LE_DYN_END	0x00ff
+
 /* channel identifier */
 #define L2CAP_CID_SIGNALING	0x0001
 #define L2CAP_CID_CONN_LESS	0x0002
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 1bb551527044..f401592e5837 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -58,7 +58,7 @@ static int l2cap_validate_bredr_psm(u16 psm)
 		return -EINVAL;
 
 	/* Restrict usage of well-known PSMs */
-	if (psm < 0x1001 && !capable(CAP_NET_BIND_SERVICE))
+	if (psm < L2CAP_PSM_DYN_START && !capable(CAP_NET_BIND_SERVICE))
 		return -EACCES;
 
 	return 0;
@@ -67,11 +67,11 @@ static int l2cap_validate_bredr_psm(u16 psm)
 static int l2cap_validate_le_psm(u16 psm)
 {
 	/* Valid LE_PSM ranges are defined only until 0x00ff */
-	if (psm > 0x00ff)
+	if (psm > L2CAP_PSM_LE_DYN_END)
 		return -EINVAL;
 
 	/* Restrict fixed, SIG assigned PSM values to CAP_NET_BIND_SERVICE */
-	if (psm <= 0x007f && !capable(CAP_NET_BIND_SERVICE))
+	if (psm < L2CAP_PSM_LE_DYN_START && !capable(CAP_NET_BIND_SERVICE))
 		return -EACCES;
 
 	return 0;
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] Bluetooth: L2CAP: Fix auto-allocating LE PSM values
  2016-01-26 22:19 [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges Johan Hedberg
@ 2016-01-26 22:19 ` Johan Hedberg
  2016-01-27 15:26   ` Marcel Holtmann
  2016-01-26 22:19 ` [PATCH 3/3] Bluetooth: L2CAP: Fix setting chan src info before adding PSM/CID Johan Hedberg
  2016-01-27 15:26 ` [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges Marcel Holtmann
  2 siblings, 1 reply; 6+ messages in thread
From: Johan Hedberg @ 2016-01-26 22:19 UTC (permalink / raw)
  To: linux-bluetooth

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

The LE dynamic PSM range is different from BR/EDR (0x0080 - 0x00ff)
and doesn't have requirements relating to parity, so separate checks
are needed.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_core.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 39a5149f3010..eb4f5f24cbe3 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -197,10 +197,20 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
 		chan->sport = psm;
 		err = 0;
 	} else {
-		u16 p;
+		u16 p, start, end, incr;
+
+		if (chan->src_type == BDADDR_BREDR) {
+			start = L2CAP_PSM_DYN_START;
+			end = L2CAP_PSM_AUTO_END;
+			incr = 2;
+		} else {
+			start = L2CAP_PSM_LE_DYN_START;
+			end = L2CAP_PSM_LE_DYN_END;
+			incr = 1;
+		}
 
 		err = -EINVAL;
-		for (p = 0x1001; p < 0x1100; p += 2)
+		for (p = start; p <= end; p += incr)
 			if (!__l2cap_global_chan_by_addr(cpu_to_le16(p), src)) {
 				chan->psm   = cpu_to_le16(p);
 				chan->sport = cpu_to_le16(p);
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] Bluetooth: L2CAP: Fix setting chan src info before adding PSM/CID
  2016-01-26 22:19 [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges Johan Hedberg
  2016-01-26 22:19 ` [PATCH 2/3] Bluetooth: L2CAP: Fix auto-allocating LE PSM values Johan Hedberg
@ 2016-01-26 22:19 ` Johan Hedberg
  2016-01-27 15:26   ` Marcel Holtmann
  2016-01-27 15:26 ` [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges Marcel Holtmann
  2 siblings, 1 reply; 6+ messages in thread
From: Johan Hedberg @ 2016-01-26 22:19 UTC (permalink / raw)
  To: linux-bluetooth

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

At least the l2cap_add_psm() routine depends on the source address
type being properly set to know what auto-allocation ranges to use, so
the assignment to l2cap_chan needs to happen before this.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/l2cap_sock.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index f401592e5837..e4cae72895a7 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -125,6 +125,9 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 			goto done;
 	}
 
+	bacpy(&chan->src, &la.l2_bdaddr);
+	chan->src_type = la.l2_bdaddr_type;
+
 	if (la.l2_cid)
 		err = l2cap_add_scid(chan, __le16_to_cpu(la.l2_cid));
 	else
@@ -156,9 +159,6 @@ static int l2cap_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 		break;
 	}
 
-	bacpy(&chan->src, &la.l2_bdaddr);
-	chan->src_type = la.l2_bdaddr_type;
-
 	if (chan->psm && bdaddr_type_is_le(chan->src_type))
 		chan->mode = L2CAP_MODE_LE_FLOWCTL;
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/3] Bluetooth: L2CAP: Fix auto-allocating LE PSM values
  2016-01-26 22:19 ` [PATCH 2/3] Bluetooth: L2CAP: Fix auto-allocating LE PSM values Johan Hedberg
@ 2016-01-27 15:26   ` Marcel Holtmann
  0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2016-01-27 15:26 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> The LE dynamic PSM range is different from BR/EDR (0x0080 - 0x00ff)
> and doesn't have requirements relating to parity, so separate checks
> are needed.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/l2cap_core.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges
  2016-01-26 22:19 [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges Johan Hedberg
  2016-01-26 22:19 ` [PATCH 2/3] Bluetooth: L2CAP: Fix auto-allocating LE PSM values Johan Hedberg
  2016-01-26 22:19 ` [PATCH 3/3] Bluetooth: L2CAP: Fix setting chan src info before adding PSM/CID Johan Hedberg
@ 2016-01-27 15:26 ` Marcel Holtmann
  2 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2016-01-27 15:26 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> Having proper defines makes the code a bit readable, it also avoids
> duplicating hard-coded values since these are also needed when
> auto-allocating PSM values (in a subsequent patch).
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> include/net/bluetooth/l2cap.h | 6 ++++++
> net/bluetooth/l2cap_sock.c    | 6 +++---
> 2 files changed, 9 insertions(+), 3 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] Bluetooth: L2CAP: Fix setting chan src info before adding PSM/CID
  2016-01-26 22:19 ` [PATCH 3/3] Bluetooth: L2CAP: Fix setting chan src info before adding PSM/CID Johan Hedberg
@ 2016-01-27 15:26   ` Marcel Holtmann
  0 siblings, 0 replies; 6+ messages in thread
From: Marcel Holtmann @ 2016-01-27 15:26 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> At least the l2cap_add_psm() routine depends on the source address
> type being properly set to know what auto-allocation ranges to use, so
> the assignment to l2cap_chan needs to happen before this.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/l2cap_sock.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-01-27 15:26 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-01-26 22:19 [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges Johan Hedberg
2016-01-26 22:19 ` [PATCH 2/3] Bluetooth: L2CAP: Fix auto-allocating LE PSM values Johan Hedberg
2016-01-27 15:26   ` Marcel Holtmann
2016-01-26 22:19 ` [PATCH 3/3] Bluetooth: L2CAP: Fix setting chan src info before adding PSM/CID Johan Hedberg
2016-01-27 15:26   ` Marcel Holtmann
2016-01-27 15:26 ` [PATCH 1/3] Bluetooth: L2CAP: Introduce proper defines for PSM ranges Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox