Skip to content

Commit

Permalink
Bluetooth: EWS: fix max_pdu calculation
Browse files Browse the repository at this point in the history
Fix max_pdu_size calculationin for RFC. Change magic number to human readable
defines.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
  • Loading branch information
finikorg authored and Gustavo F. Padovan committed Oct 17, 2011
1 parent 03a5121 commit c8f7916
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions net/bluetooth/l2cap_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
struct l2cap_conf_req *req = data;
struct l2cap_conf_rfc rfc = { .mode = chan->mode };
void *ptr = req->data;
u16 size;

BT_DBG("chan %p", chan);

Expand Down Expand Up @@ -2037,9 +2038,12 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
rfc.max_transmit = chan->max_tx;
rfc.retrans_timeout = 0;
rfc.monitor_timeout = 0;
rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
if (L2CAP_DEFAULT_MAX_PDU_SIZE > chan->conn->mtu - 10)
rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);

size = min_t(u16, L2CAP_DEFAULT_MAX_PDU_SIZE, chan->conn->mtu -
L2CAP_EXT_HDR_SIZE -
L2CAP_SDULEN_SIZE -
L2CAP_FCS_SIZE);
rfc.max_pdu_size = cpu_to_le16(size);

l2cap_txwin_setup(chan);

Expand Down Expand Up @@ -2072,9 +2076,12 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
rfc.max_transmit = 0;
rfc.retrans_timeout = 0;
rfc.monitor_timeout = 0;
rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
if (L2CAP_DEFAULT_MAX_PDU_SIZE > chan->conn->mtu - 10)
rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);

size = min_t(u16, L2CAP_DEFAULT_MAX_PDU_SIZE, chan->conn->mtu -
L2CAP_EXT_HDR_SIZE -
L2CAP_SDULEN_SIZE -
L2CAP_FCS_SIZE);
rfc.max_pdu_size = cpu_to_le16(size);

l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
(unsigned long) &rfc);
Expand Down Expand Up @@ -2110,6 +2117,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
u16 mtu = L2CAP_DEFAULT_MTU;
u16 result = L2CAP_CONF_SUCCESS;
u16 size;

BT_DBG("chan %p", chan);

Expand Down Expand Up @@ -2219,10 +2227,13 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)

chan->remote_max_tx = rfc.max_transmit;

if (le16_to_cpu(rfc.max_pdu_size) > chan->conn->mtu - 10)
rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);

chan->remote_mps = le16_to_cpu(rfc.max_pdu_size);
size = min_t(u16, le16_to_cpu(rfc.max_pdu_size),
chan->conn->mtu -
L2CAP_EXT_HDR_SIZE -
L2CAP_SDULEN_SIZE -
L2CAP_FCS_SIZE);
rfc.max_pdu_size = cpu_to_le16(size);
chan->remote_mps = size;

rfc.retrans_timeout =
le16_to_cpu(L2CAP_DEFAULT_RETRANS_TO);
Expand All @@ -2237,10 +2248,13 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
break;

case L2CAP_MODE_STREAMING:
if (le16_to_cpu(rfc.max_pdu_size) > chan->conn->mtu - 10)
rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);

chan->remote_mps = le16_to_cpu(rfc.max_pdu_size);
size = min_t(u16, le16_to_cpu(rfc.max_pdu_size),
chan->conn->mtu -
L2CAP_EXT_HDR_SIZE -
L2CAP_SDULEN_SIZE -
L2CAP_FCS_SIZE);
rfc.max_pdu_size = cpu_to_le16(size);
chan->remote_mps = size;

set_bit(CONF_MODE_DONE, &chan->conf_state);

Expand Down

0 comments on commit c8f7916

Please sign in to comment.