l2test: Fix setting mode for BR/EDR l2cap socket
authorSimon Mikuda <simon.mikuda@streamunlimited.com>
Tue, 28 Mar 2023 05:26:19 +0000 (07:26 +0200)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 10:41:34 +0000 (16:11 +0530)
BT_MODE_* enums are used only for socket SOL_BLUETOOTH, option BT_MODE
Otherwise we should use L2CAP_MODE_* enums.

lib/l2cap.h
tools/l2test.c

index 30bc9b1..8593a6f 100755 (executable)
@@ -196,6 +196,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
index e70ed67..b0dccc9 100755 (executable)
@@ -165,6 +165,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;
@@ -297,9 +315,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,