Bluetooth: L2CAP: Fix returning correct LE CoC response codes
[firefly-linux-kernel-4.4.55.git] / net / bluetooth / l2cap_core.c
index 7c65ee200c29215c6b3f050cfbb881873be4946a..8fd36f59dcdef344d02d5d6f27df5a4af4d561e5 100644 (file)
@@ -5437,9 +5437,16 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,
                goto response_unlock;
        }
 
+       /* Check for valid dynamic CID range */
+       if (scid < L2CAP_CID_DYN_START || scid > L2CAP_CID_LE_DYN_END) {
+               result = L2CAP_CR_INVALID_SCID;
+               chan = NULL;
+               goto response_unlock;
+       }
+
        /* Check if we already have channel with that dcid */
        if (__l2cap_get_chan_by_dcid(conn, scid)) {
-               result = L2CAP_CR_NO_MEM;
+               result = L2CAP_CR_SCID_IN_USE;
                chan = NULL;
                goto response_unlock;
        }