diff mbox series

[BlueZ,2/2] l2test: Fix setting mode for BR/EDR l2cap socket

Message ID 20230323102732.566440-3-simon.mikuda@streamunlimited.com (mailing list archive)
State New, archived
Headers show
Series l2test fix+feature | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch fail ERROR:SWITCH_CASE_INDENT_LEVEL: switch and case should be at the same indent #108: FILE: tools/l2test.c:160: + switch (mode) { + case BT_MODE_BASIC: [...] + case BT_MODE_ERTM: [...] + case BT_MODE_STREAMING: [...] + case BT_MODE_LE_FLOWCTL: [...] + case BT_MODE_EXT_FLOWCTL: [...] + default: /github/workspace/src/src/13185459.patch total: 1 errors, 0 warnings, 44 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/src/13185459.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Simon Mikuda March 23, 2023, 10:27 a.m. UTC
BT_MODE_* enums are used only for socket SOL_BLUETOOTH, option BT_MODE
Otherwise we should use L2CAP_MODE_* enums.
---
 lib/l2cap.h    |  2 ++
 tools/l2test.c | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/lib/l2cap.h b/lib/l2cap.h
index 9197800df..62cc04b57 100644
--- a/lib/l2cap.h
+++ b/lib/l2cap.h
@@ -184,6 +184,8 @@  typedef struct {
 #define L2CAP_MODE_FLOWCTL	0x02
 #define L2CAP_MODE_ERTM		0x03
 #define L2CAP_MODE_STREAMING	0x04
+#define L2CAP_MODE_LE_FLOWCTL	0x80
+#define L2CAP_MODE_ECRED		0x81
 
 #define L2CAP_SERVTYPE_NOTRAFFIC	0x00
 #define L2CAP_SERVTYPE_BESTEFFORT	0x01
diff --git a/tools/l2test.c b/tools/l2test.c
index 595f1dab2..61b2e778e 100644
--- a/tools/l2test.c
+++ b/tools/l2test.c
@@ -155,6 +155,24 @@  static struct lookup_table bdaddr_types[] = {
 	{ NULL,		0			},
 };
 
+static int bt_mode_to_l2cap_mode(int mode)
+{
+	switch (mode) {
+		case BT_MODE_BASIC:
+			return L2CAP_MODE_BASIC;
+		case BT_MODE_ERTM:
+			return L2CAP_MODE_ERTM;
+		case BT_MODE_STREAMING:
+			return L2CAP_MODE_STREAMING;
+		case BT_MODE_LE_FLOWCTL:
+			return L2CAP_MODE_LE_FLOWCTL;
+		case BT_MODE_EXT_FLOWCTL:
+			return L2CAP_MODE_FLOWCTL;
+		default:
+			return mode;
+	}
+}
+
 static int get_lookup_flag(struct lookup_table *table, char *name)
 {
 	int i;
@@ -287,9 +305,11 @@  static int getopts(int sk, struct l2cap_options *opts, bool connected)
 
 static int setopts(int sk, struct l2cap_options *opts)
 {
-	if (bdaddr_type == BDADDR_BREDR)
+	if (bdaddr_type == BDADDR_BREDR) {
+		opts->mode = bt_mode_to_l2cap_mode(opts->mode);
 		return setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, opts,
 								sizeof(*opts));
+	}
 
 	if (opts->mode) {
 		if (setsockopt(sk, SOL_BLUETOOTH, BT_MODE, &opts->mode,