Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH 1/2] monitor: Factor out channel selection to separate function
@ 2015-02-18 21:46 Szymon Janc
  2015-02-18 21:46 ` [PATCH 2/2] monitor: Fix selecting PSM for L2CAP frame Szymon Janc
  2015-02-19  8:21 ` [PATCH 1/2] monitor: Factor out channel selection to separate function Johan Hedberg
  0 siblings, 2 replies; 3+ messages in thread
From: Szymon Janc @ 2015-02-18 21:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

This allows to have conditions check in single place.
---
 monitor/l2cap.c | 85 +++++++++++++++++----------------------------------------
 1 file changed, 25 insertions(+), 60 deletions(-)

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index 0030a4c..342bd8e 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -223,7 +223,7 @@ static void assign_mode(const struct l2cap_frame *frame,
 	}
 }
 
-static uint16_t get_psm(const struct l2cap_frame *frame)
+static int get_chan_data_index(const struct l2cap_frame *frame)
 {
 	int i;
 
@@ -238,64 +238,44 @@ static uint16_t get_psm(const struct l2cap_frame *frame)
 
 		if (frame->in) {
 			if (chan_list[i].scid == frame->cid)
-				return chan_list[i].psm;
+				return i;
 		} else {
 			if (chan_list[i].dcid == frame->cid)
-				return chan_list[i].psm;
+				return i;
 		}
 	}
 
-	return 0;
+	return -1;
 }
 
-static uint8_t get_mode(const struct l2cap_frame *frame)
+static uint16_t get_psm(const struct l2cap_frame *frame)
 {
-	int i;
+	int i = get_chan_data_index(frame);
 
-	for (i = 0; i < MAX_CHAN; i++) {
-		if (chan_list[i].index != frame->index &&
-					chan_list[i].ctrlid == 0)
-			continue;
+	if (i < 0)
+		return 0;
 
-		if (chan_list[i].handle != frame->handle &&
-					chan_list[i].ctrlid != frame->index)
-			continue;
+	return chan_list[i].psm;
+}
 
-		if (frame->in) {
-			if (chan_list[i].scid == frame->cid)
-				return chan_list[i].mode;
-		} else {
-			if (chan_list[i].dcid == frame->cid)
-				return chan_list[i].mode;
-		}
-	}
+static uint8_t get_mode(const struct l2cap_frame *frame)
+{
+	int i = get_chan_data_index(frame);
+
+	if (i < 0)
+		return 0;
 
-	return 0;
+	return chan_list[i].mode;
 }
 
 static uint16_t get_chan(const struct l2cap_frame *frame)
 {
-	int i;
-
-	for (i = 0; i < MAX_CHAN; i++) {
-		if (chan_list[i].index != frame->index &&
-					chan_list[i].ctrlid == 0)
-			continue;
+	int i = get_chan_data_index(frame);
 
-		if (chan_list[i].handle != frame->handle &&
-					chan_list[i].ctrlid != frame->index)
-			continue;
-
-		if (frame->in) {
-			if (chan_list[i].scid == frame->cid)
-				return i;
-		} else {
-			if (chan_list[i].dcid == frame->cid)
-				return i;
-		}
-	}
+	if (i < 0)
+		return 0;
 
-	return 0;
+	return i;
 }
 
 static void assign_ext_ctrl(const struct l2cap_frame *frame,
@@ -326,27 +306,12 @@ static void assign_ext_ctrl(const struct l2cap_frame *frame,
 
 static uint8_t get_ext_ctrl(const struct l2cap_frame *frame)
 {
-	int i;
+	int i = get_chan_data_index(frame);
 
-	for (i = 0; i < MAX_CHAN; i++) {
-		if (chan_list[i].index != frame->index &&
-						chan_list[i].ctrlid == 0)
-			continue;
-
-		if (chan_list[i].handle != frame->handle &&
-					chan_list[i].ctrlid != frame->index)
-			continue;
-
-		if (frame->in) {
-			if (chan_list[i].scid == frame->cid)
-				return chan_list[i].ext_ctrl;
-		} else {
-			if (chan_list[i].dcid == frame->cid)
-				return chan_list[i].ext_ctrl;
-		}
-	}
+	if (i < 0)
+		return 0;
 
-	return 0;
+	return chan_list[i].ext_ctrl;
 }
 
 static char *sar2str(uint8_t sar)
-- 
1.9.3


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

* [PATCH 2/2] monitor: Fix selecting PSM for L2CAP frame
  2015-02-18 21:46 [PATCH 1/2] monitor: Factor out channel selection to separate function Szymon Janc
@ 2015-02-18 21:46 ` Szymon Janc
  2015-02-19  8:21 ` [PATCH 1/2] monitor: Factor out channel selection to separate function Johan Hedberg
  1 sibling, 0 replies; 3+ messages in thread
From: Szymon Janc @ 2015-02-18 21:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Current code could fail to pick up right PSM resulting in using PSM 1
for non-SDP traffic.

Fix following:
> ACL Data RX: Handle 3 flags 0x02 dlen 9
    Channel: 64 len 5 [PSM 1 mode 0] {chan 0}
      invalid frame size
> ACL Data RX: Handle 3 flags 0x02 dlen 20
    Channel: 64 len 16 [PSM 1 mode 0] {chan 0}
      invalid frame size
      2b 42 52 53 46 3d 32 35 35 0d e4                 +BRSF=255..
< ACL Data TX: Handle 3 flags 0x00 dlen 28
    Channel: 256 len 24 [PSM 3 mode 0] {chan 1}
    RFCOMM: Unnumbered Info with Header Check (UIH)(0xef)
       Address: 0x69 cr 0 dlci 0x1a
       Control: 0xef poll/final 0
       Length: 20
       FCS: 0x3e
      0d 0a 2b 42 52 53 46 3a 20 38 37 31 0d 0a 0d 0a  ..+BRSF: 871....
      4f 4b 0d 0a 3e                                   OK..>

instead of:
> ACL Data RX: Handle 4 flags 0x02 dlen 20
    Channel: 64 len 16 [PSM 3 mode 0] {chan 1}
    RFCOMM: Unnumbered Info with Header Check (UIH)(0xef)
       Address: 0x6b cr 1 dlci 0x1a
       Control: 0xef poll/final 0
       Length: 12
       FCS: 0xe4
      41 54 2b 42 52 53 46 3d 32 35 35 0d e4           AT+BRSF=255..
< ACL Data TX: Handle 4 flags 0x00 dlen 28
    Channel: 384 len 24 [PSM 3 mode 0] {chan 1}
    RFCOMM: Unnumbered Info with Header Check (UIH)(0xef)
       Address: 0x69 cr 0 dlci 0x1a
       Control: 0xef poll/final 0
       Length: 20
       FCS: 0x3e
      0d 0a 2b 42 52 53 46 3a 20 38 37 31 0d 0a 0d 0a  ..+BRSF: 871....
      4f 4b 0d 0a 3e                                   OK..>
---
 monitor/l2cap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/monitor/l2cap.c b/monitor/l2cap.c
index 342bd8e..7a6edbe 100644
--- a/monitor/l2cap.c
+++ b/monitor/l2cap.c
@@ -232,10 +232,13 @@ static int get_chan_data_index(const struct l2cap_frame *frame)
 					chan_list[i].ctrlid == 0)
 			continue;
 
-		if (chan_list[i].handle != frame->handle &&
+		if (chan_list[i].ctrlid != 0 &&
 					chan_list[i].ctrlid != frame->index)
 			continue;
 
+		if (chan_list[i].handle != frame->handle)
+			continue;
+
 		if (frame->in) {
 			if (chan_list[i].scid == frame->cid)
 				return i;
-- 
1.9.3


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

* Re: [PATCH 1/2] monitor: Factor out channel selection to separate function
  2015-02-18 21:46 [PATCH 1/2] monitor: Factor out channel selection to separate function Szymon Janc
  2015-02-18 21:46 ` [PATCH 2/2] monitor: Fix selecting PSM for L2CAP frame Szymon Janc
@ 2015-02-19  8:21 ` Johan Hedberg
  1 sibling, 0 replies; 3+ messages in thread
From: Johan Hedberg @ 2015-02-19  8:21 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth

Hi Szymon,

On Wed, Feb 18, 2015, Szymon Janc wrote:
> This allows to have conditions check in single place.
> ---
>  monitor/l2cap.c | 85 +++++++++++++++++----------------------------------------
>  1 file changed, 25 insertions(+), 60 deletions(-)

Both patches have been applied. Thanks.

Johan

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

end of thread, other threads:[~2015-02-19  8:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-18 21:46 [PATCH 1/2] monitor: Factor out channel selection to separate function Szymon Janc
2015-02-18 21:46 ` [PATCH 2/2] monitor: Fix selecting PSM for L2CAP frame Szymon Janc
2015-02-19  8:21 ` [PATCH 1/2] monitor: Factor out channel selection to separate function Johan Hedberg

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