monitor/att: Fix not matching read frame direction
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 20 May 2022 23:36:57 +0000 (16:36 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
There could be read frames pending on both direction so this ensures
the direction is matched properly.

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
monitor/att.c

index 4b8bffb..d0e44b2 100644 (file)
@@ -403,7 +403,8 @@ static void att_read_type_rsp(const struct l2cap_frame *frame)
 
 struct att_read {
        struct gatt_db_attribute *attr;
-       uint16_t cid;
+       bool in;
+       uint16_t chan;
        void (*func)(const struct l2cap_frame *frame);
 };
 
@@ -552,7 +553,8 @@ static void att_read_req(const struct l2cap_frame *frame)
 
        read = new0(struct att_read, 1);
        read->attr = attr;
-       read->cid = frame->cid;
+       read->in = frame->in;
+       read->chan = frame->chan;
        read->func = handler->read;
 
        queue_push_tail(data->reads, read);
@@ -563,7 +565,13 @@ static bool match_read_frame(const void *data, const void *match_data)
        const struct att_read *read = data;
        const struct l2cap_frame *frame = match_data;
 
-       return read->cid == frame->cid;
+       /* Read frame and response frame shall be in the opposite direction to
+        * match.
+        */
+       if (read->in == frame->in)
+               return false;
+
+       return read->chan == frame->chan;
 }
 
 static void att_read_rsp(const struct l2cap_frame *frame)