Skip to contentSkip to conversation

btio: Fix not translation mode to L2CAP mode

PATCH In review Luiz Augusto von Dentz 2 participants 4 messages Jun 5, 2020 – Jun 8, 2020 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 btio: Fix not translation mode to L2CAP mode

From: Luiz Augusto von Dentz <[email protected]>

When using L2CAP_OPTIONS legacy modes need to be used since they are not compatible with BT_MODE.

---
 btio/btio.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
btio/btio.c +22 -2
index 13c731062..844d6007f 100644
@@ -597,6 +597,20 @@ static gboolean get_key_size(int sock, int *size, GError **err)
 	return FALSE;
 }
 
+static uint8_t mode_l2mode(uint8_t mode)
+{
+	switch (mode) {
+	case BT_IO_MODE_BASIC:
+		return L2CAP_MODE_BASIC;
+	case BT_IO_MODE_ERTM:
+		return L2CAP_MODE_ERTM;
+	case BT_IO_MODE_STREAMING:
+		return L2CAP_MODE_STREAMING;
+	default:
+		return UINT8_MAX;
+	}
+}
+
 static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
 						uint8_t mode, GError **err)
 {
@@ -614,8 +628,14 @@ static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
 		l2o.imtu = imtu;
 	if (omtu)
 		l2o.omtu = omtu;
-	if (mode)
-		l2o.mode = mode;
+
+	if (mode) {
+		l2o.mode = mode_l2mode(mode);
+		if (l2o.mode == UINT8_MAX) {
+			ERROR_FAILED(err, "Unsupported mode", errno);
+			return FALSE;
+		}
+	}
 
 	if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)) < 0) {
 		ERROR_FAILED(err, "setsockopt(L2CAP_OPTIONS)", errno);
Signature · 1 line
2.25.3
author maintainer
#1 lore raw

Hi,

Quoted 52 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

When using L2CAP_OPTIONS legacy modes need to be used since they are not compatible with BT_MODE.

---
 btio/btio.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
btio/btio.c +22 -3
index 13c731062..844d6007f 100644
@@ -597,6 +597,20 @@ static gboolean get_key_size(int sock, int *size, GError **err)
        return FALSE;
 }
 
+static uint8_t mode_l2mode(uint8_t mode)
+{
+       switch (mode) {
+       case BT_IO_MODE_BASIC:
+               return L2CAP_MODE_BASIC;
+       case BT_IO_MODE_ERTM:
+               return L2CAP_MODE_ERTM;
+       case BT_IO_MODE_STREAMING:
+               return L2CAP_MODE_STREAMING;
+       default:
+               return UINT8_MAX;
+       }
+}
+
 static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
                                                uint8_t mode, GError **err)
 {
@@ -614,8 +628,14 @@ static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
                l2o.imtu = imtu;
        if (omtu)
                l2o.omtu = omtu;
-       if (mode)
-               l2o.mode = mode;
+
+       if (mode) {
+               l2o.mode = mode_l2mode(mode);
+               if (l2o.mode == UINT8_MAX) {
+                       ERROR_FAILED(err, "Unsupported mode", errno);
+                       return FALSE;
+               }
+       }
 
        if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)) < 0) {
                ERROR_FAILED(err, "setsockopt(L2CAP_OPTIONS)", errno);
--
Quoted 1 line

2.25.3

Pushed.

Signature · 1 line
Luiz Augusto von Dentz
#2 lore raw

Hi Luiz,

Quoted 60 lines

Hi,

Quoted 52 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

When using L2CAP_OPTIONS legacy modes need to be used since they are not compatible with BT_MODE.

---
 btio/btio.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
btio/btio.c +22 -3
index 13c731062..844d6007f 100644
@@ -597,6 +597,20 @@ static gboolean get_key_size(int sock, int *size, GError **err)
        return FALSE;
 }
 
+static uint8_t mode_l2mode(uint8_t mode)
+{
+       switch (mode) {
+       case BT_IO_MODE_BASIC:
+               return L2CAP_MODE_BASIC;
+       case BT_IO_MODE_ERTM:
+               return L2CAP_MODE_ERTM;
+       case BT_IO_MODE_STREAMING:
+               return L2CAP_MODE_STREAMING;
+       default:
+               return UINT8_MAX;
+       }
+}
+
 static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
                                                uint8_t mode, GError **err)
 {
@@ -614,8 +628,14 @@ static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
                l2o.imtu = imtu;
        if (omtu)
                l2o.omtu = omtu;
-       if (mode)
-               l2o.mode = mode;
+
+       if (mode) {
+               l2o.mode = mode_l2mode(mode);
+               if (l2o.mode == UINT8_MAX) {
+                       ERROR_FAILED(err, "Unsupported mode", errno);
+                       return FALSE;
+               }
+       }
 
        if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)) < 0) {
                ERROR_FAILED(err, "setsockopt(L2CAP_OPTIONS)", errno);
--
Quoted 1 line

2.25.3

Pushed.

Quoted 2 lines

--
Luiz Augusto von Dentz

This patch seems to break avctp browsing. The creation of browsing_io in avctp_register already uses L2CAP_MODE_ERTM which is not in the switch-case hence results in "Unsupported mode". What is the desired way to fix this? Should all those calls use BT_IO_MODE_* instead? Not to mention the uses of these functions should be checked for their enum usage as well.

- Marijn Suijten

author maintainer
#3 lore raw

Hi Marijn,

Quoted 66 lines · Marijn Suijten

Hi Luiz,

Quoted 60 lines

Hi,

Quoted 52 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

When using L2CAP_OPTIONS legacy modes need to be used since they are not compatible with BT_MODE.

---
 btio/btio.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
btio/btio.c +22 -3
index 13c731062..844d6007f 100644
@@ -597,6 +597,20 @@ static gboolean get_key_size(int sock, int *size, GError **err)
        return FALSE;
 }
 
+static uint8_t mode_l2mode(uint8_t mode)
+{
+       switch (mode) {
+       case BT_IO_MODE_BASIC:
+               return L2CAP_MODE_BASIC;
+       case BT_IO_MODE_ERTM:
+               return L2CAP_MODE_ERTM;
+       case BT_IO_MODE_STREAMING:
+               return L2CAP_MODE_STREAMING;
+       default:
+               return UINT8_MAX;
+       }
+}
+
 static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
                                                uint8_t mode, GError **err)
 {
@@ -614,8 +628,14 @@ static gboolean set_l2opts(int sock, uint16_t imtu, uint16_t omtu,
                l2o.imtu = imtu;
        if (omtu)
                l2o.omtu = omtu;
-       if (mode)
-               l2o.mode = mode;
+
+       if (mode) {
+               l2o.mode = mode_l2mode(mode);
+               if (l2o.mode == UINT8_MAX) {
+                       ERROR_FAILED(err, "Unsupported mode", errno);
+                       return FALSE;
+               }
+       }
 
        if (setsockopt(sock, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o)) < 0) {
                ERROR_FAILED(err, "setsockopt(L2CAP_OPTIONS)", errno);
--
Quoted 1 line

2.25.3

Pushed.

Quoted 2 lines

--
Luiz Augusto von Dentz

Quoted 6 lines

This patch seems to break avctp browsing. The creation of browsing_io in avctp_register already uses L2CAP_MODE_ERTM which is not in the switch-case hence results in "Unsupported mode". What is the desired way to fix this? Should all those calls use BT_IO_MODE_* instead? Not to mention the uses of these functions should be checked for their enum usage as well.

I will fix it, bt_io API shall only operate with the its mode not L2CAP mode so it is a bug to pass them.

Signature · 1 line
Luiz Augusto von Dentz