Bluetooth: Get a more accurate L2CAP PDU len
authorGustavo Padovan <gustavo.padovan@collabora.co.uk>
Fri, 25 May 2012 21:57:05 +0000 (18:57 -0300)
committerJohan Hedberg <johan.hedberg@intel.com>
Tue, 5 Jun 2012 03:34:09 +0000 (06:34 +0300)
Both FCS and Extended header might be or might not be present in a ERTM
channel.

Signed-off-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk>
Reviewed-by: Mat Martineau <mathewm@codeaurora.org>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/l2cap_core.c

index 6eb2ef2de7238c0ef982450b93b5224889124ddb..155aa509b3afd7e4fdb420fd6772a27f0e071965 100644 (file)
@@ -2130,7 +2130,13 @@ static int l2cap_segment_sdu(struct l2cap_chan *chan,
        pdu_len = min_t(size_t, pdu_len, L2CAP_BREDR_MAX_PAYLOAD);
 
        /* Adjust for largest possible L2CAP overhead. */
-       pdu_len -= L2CAP_EXT_HDR_SIZE + L2CAP_FCS_SIZE;
+       if (chan->fcs)
+               pdu_len -= L2CAP_FCS_SIZE;
+
+       if (test_bit(FLAG_EXT_CTRL, &chan->flags))
+               pdu_len -= L2CAP_EXT_HDR_SIZE;
+       else
+               pdu_len -= L2CAP_ENH_HDR_SIZE;
 
        /* Remote device may have requested smaller PDUs */
        pdu_len = min_t(size_t, pdu_len, chan->remote_mps);