• Sebastian Urban's avatar
    Bluetooth: compute LE flow credits based on recvbuf space · ce60b923
    Sebastian Urban authored
    Previously LE flow credits were returned to the
    sender even if the socket's receive buffer was
    full. This meant that no back-pressure
    was applied to the sender, thus it continued to
    send data, resulting in data loss without any
    error being reported. Furthermore, the amount
    of credits was essentially fixed to a small
    amount, leading to reduced performance.
    
    This is fixed by computing the number of returned
    LE flow credits based on the estimated available
    space in the receive buffer of an L2CAP socket.
    Consequently, if the receive buffer is full, no
    credits are returned until the buffer is read and
    thus cleared by user-space.
    
    Since the computation of available receive buffer
    space can only be performed approximately (due to
    sk_buff overhead) and the receive buffer size may
    be changed by user-space after flow credits have
    been sent, superfluous received data is temporary
    stored within l2cap_pinfo. This is necessary
    because Bluetooth LE provides no retransmission
    mechanism once the data has been acked by the
    physical layer.
    
    If receive buffer space estimation is not possible
    at the moment, we fall back to providing credits
    for one full packet as before. This is currently
    the case during connection setup, when MPS is not
    yet available.
    
    Fixes: b1c325c2 ("Bluetooth: Implement returning of LE L2CAP credits")
    Signed-off-by: default avatarSebastian Urban <surban@surban.net>
    Signed-off-by: default avatarLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
    ce60b923
l2cap_core.c 179 KB