diff options
author | Andrei Emeltchenko <andrei.emeltchenko@intel.com> | 2011-10-17 05:19:58 -0400 |
---|---|---|
committer | Gustavo F. Padovan <padovan@profusion.mobi> | 2011-10-17 16:04:14 -0400 |
commit | 03a512137da58e18bec15b46c409a62e0250447e (patch) | |
tree | 0696e14fe7d42be7e30e0dc85513a0810a4b72b9 /net/bluetooth/l2cap_core.c | |
parent | 836be934218eb80abc5515d584c329c26951086f (diff) |
Bluetooth: EWS: remove magic numbers in l2cap
Remove magic numbers for FCS, SDU LEN and PSM LEN
when calculating packet payload.
Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
Diffstat (limited to 'net/bluetooth/l2cap_core.c')
-rw-r--r-- | net/bluetooth/l2cap_core.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 86c8720043e..aa33499798a 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c | |||
@@ -585,7 +585,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control) | |||
585 | hlen = L2CAP_ENH_HDR_SIZE; | 585 | hlen = L2CAP_ENH_HDR_SIZE; |
586 | 586 | ||
587 | if (chan->fcs == L2CAP_FCS_CRC16) | 587 | if (chan->fcs == L2CAP_FCS_CRC16) |
588 | hlen += 2; | 588 | hlen += L2CAP_FCS_SIZE; |
589 | 589 | ||
590 | BT_DBG("chan %p, control 0x%8.8x", chan, control); | 590 | BT_DBG("chan %p, control 0x%8.8x", chan, control); |
591 | 591 | ||
@@ -610,8 +610,8 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control) | |||
610 | __put_control(chan, control, skb_put(skb, __ctrl_size(chan))); | 610 | __put_control(chan, control, skb_put(skb, __ctrl_size(chan))); |
611 | 611 | ||
612 | if (chan->fcs == L2CAP_FCS_CRC16) { | 612 | if (chan->fcs == L2CAP_FCS_CRC16) { |
613 | u16 fcs = crc16(0, (u8 *)lh, count - 2); | 613 | u16 fcs = crc16(0, (u8 *)lh, count - L2CAP_FCS_SIZE); |
614 | put_unaligned_le16(fcs, skb_put(skb, 2)); | 614 | put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE)); |
615 | } | 615 | } |
616 | 616 | ||
617 | if (lmp_no_flush_capable(conn->hcon->hdev)) | 617 | if (lmp_no_flush_capable(conn->hcon->hdev)) |
@@ -1289,8 +1289,10 @@ static void l2cap_streaming_send(struct l2cap_chan *chan) | |||
1289 | __put_control(chan, control, skb->data + L2CAP_HDR_SIZE); | 1289 | __put_control(chan, control, skb->data + L2CAP_HDR_SIZE); |
1290 | 1290 | ||
1291 | if (chan->fcs == L2CAP_FCS_CRC16) { | 1291 | if (chan->fcs == L2CAP_FCS_CRC16) { |
1292 | fcs = crc16(0, (u8 *)skb->data, skb->len - 2); | 1292 | fcs = crc16(0, (u8 *)skb->data, |
1293 | put_unaligned_le16(fcs, skb->data + skb->len - 2); | 1293 | skb->len - L2CAP_FCS_SIZE); |
1294 | put_unaligned_le16(fcs, | ||
1295 | skb->data + skb->len - L2CAP_FCS_SIZE); | ||
1294 | } | 1296 | } |
1295 | 1297 | ||
1296 | l2cap_do_send(chan, skb); | 1298 | l2cap_do_send(chan, skb); |
@@ -1339,8 +1341,10 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq) | |||
1339 | __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); | 1341 | __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); |
1340 | 1342 | ||
1341 | if (chan->fcs == L2CAP_FCS_CRC16) { | 1343 | if (chan->fcs == L2CAP_FCS_CRC16) { |
1342 | fcs = crc16(0, (u8 *)tx_skb->data, tx_skb->len - 2); | 1344 | fcs = crc16(0, (u8 *)tx_skb->data, |
1343 | put_unaligned_le16(fcs, tx_skb->data + tx_skb->len - 2); | 1345 | tx_skb->len - L2CAP_FCS_SIZE); |
1346 | put_unaligned_le16(fcs, | ||
1347 | tx_skb->data + tx_skb->len - L2CAP_FCS_SIZE); | ||
1344 | } | 1348 | } |
1345 | 1349 | ||
1346 | l2cap_do_send(chan, tx_skb); | 1350 | l2cap_do_send(chan, tx_skb); |
@@ -1380,8 +1384,10 @@ static int l2cap_ertm_send(struct l2cap_chan *chan) | |||
1380 | __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); | 1384 | __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); |
1381 | 1385 | ||
1382 | if (chan->fcs == L2CAP_FCS_CRC16) { | 1386 | if (chan->fcs == L2CAP_FCS_CRC16) { |
1383 | fcs = crc16(0, (u8 *)skb->data, tx_skb->len - 2); | 1387 | fcs = crc16(0, (u8 *)skb->data, |
1384 | put_unaligned_le16(fcs, skb->data + tx_skb->len - 2); | 1388 | tx_skb->len - L2CAP_FCS_SIZE); |
1389 | put_unaligned_le16(fcs, skb->data + | ||
1390 | tx_skb->len - L2CAP_FCS_SIZE); | ||
1385 | } | 1391 | } |
1386 | 1392 | ||
1387 | l2cap_do_send(chan, tx_skb); | 1393 | l2cap_do_send(chan, tx_skb); |
@@ -1491,7 +1497,7 @@ static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct | |||
1491 | struct sock *sk = chan->sk; | 1497 | struct sock *sk = chan->sk; |
1492 | struct l2cap_conn *conn = chan->conn; | 1498 | struct l2cap_conn *conn = chan->conn; |
1493 | struct sk_buff *skb; | 1499 | struct sk_buff *skb; |
1494 | int err, count, hlen = L2CAP_HDR_SIZE + 2; | 1500 | int err, count, hlen = L2CAP_HDR_SIZE + L2CAP_PSMLEN_SIZE; |
1495 | struct l2cap_hdr *lh; | 1501 | struct l2cap_hdr *lh; |
1496 | 1502 | ||
1497 | BT_DBG("sk %p len %d", sk, (int)len); | 1503 | BT_DBG("sk %p len %d", sk, (int)len); |
@@ -1566,10 +1572,10 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, | |||
1566 | hlen = L2CAP_ENH_HDR_SIZE; | 1572 | hlen = L2CAP_ENH_HDR_SIZE; |
1567 | 1573 | ||
1568 | if (sdulen) | 1574 | if (sdulen) |
1569 | hlen += 2; | 1575 | hlen += L2CAP_SDULEN_SIZE; |
1570 | 1576 | ||
1571 | if (chan->fcs == L2CAP_FCS_CRC16) | 1577 | if (chan->fcs == L2CAP_FCS_CRC16) |
1572 | hlen += 2; | 1578 | hlen += L2CAP_FCS_SIZE; |
1573 | 1579 | ||
1574 | count = min_t(unsigned int, (conn->mtu - hlen), len); | 1580 | count = min_t(unsigned int, (conn->mtu - hlen), len); |
1575 | skb = bt_skb_send_alloc(sk, count + hlen, | 1581 | skb = bt_skb_send_alloc(sk, count + hlen, |
@@ -1585,7 +1591,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, | |||
1585 | __put_control(chan, control, skb_put(skb, __ctrl_size(chan))); | 1591 | __put_control(chan, control, skb_put(skb, __ctrl_size(chan))); |
1586 | 1592 | ||
1587 | if (sdulen) | 1593 | if (sdulen) |
1588 | put_unaligned_le16(sdulen, skb_put(skb, 2)); | 1594 | put_unaligned_le16(sdulen, skb_put(skb, L2CAP_SDULEN_SIZE)); |
1589 | 1595 | ||
1590 | err = l2cap_skbuff_fromiovec(sk, msg, len, count, skb); | 1596 | err = l2cap_skbuff_fromiovec(sk, msg, len, count, skb); |
1591 | if (unlikely(err < 0)) { | 1597 | if (unlikely(err < 0)) { |
@@ -1594,7 +1600,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, | |||
1594 | } | 1600 | } |
1595 | 1601 | ||
1596 | if (chan->fcs == L2CAP_FCS_CRC16) | 1602 | if (chan->fcs == L2CAP_FCS_CRC16) |
1597 | put_unaligned_le16(0, skb_put(skb, 2)); | 1603 | put_unaligned_le16(0, skb_put(skb, L2CAP_FCS_SIZE)); |
1598 | 1604 | ||
1599 | bt_cb(skb)->retries = 0; | 1605 | bt_cb(skb)->retries = 0; |
1600 | return skb; | 1606 | return skb; |
@@ -3180,7 +3186,7 @@ static int l2cap_check_fcs(struct l2cap_chan *chan, struct sk_buff *skb) | |||
3180 | hdr_size = L2CAP_ENH_HDR_SIZE; | 3186 | hdr_size = L2CAP_ENH_HDR_SIZE; |
3181 | 3187 | ||
3182 | if (chan->fcs == L2CAP_FCS_CRC16) { | 3188 | if (chan->fcs == L2CAP_FCS_CRC16) { |
3183 | skb_trim(skb, skb->len - 2); | 3189 | skb_trim(skb, skb->len - L2CAP_FCS_SIZE); |
3184 | rcv_fcs = get_unaligned_le16(skb->data + skb->len); | 3190 | rcv_fcs = get_unaligned_le16(skb->data + skb->len); |
3185 | our_fcs = crc16(0, skb->data - hdr_size, skb->len + hdr_size); | 3191 | our_fcs = crc16(0, skb->data - hdr_size, skb->len + hdr_size); |
3186 | 3192 | ||
@@ -3290,7 +3296,7 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u3 | |||
3290 | break; | 3296 | break; |
3291 | 3297 | ||
3292 | chan->sdu_len = get_unaligned_le16(skb->data); | 3298 | chan->sdu_len = get_unaligned_le16(skb->data); |
3293 | skb_pull(skb, 2); | 3299 | skb_pull(skb, L2CAP_SDULEN_SIZE); |
3294 | 3300 | ||
3295 | if (chan->sdu_len > chan->imtu) { | 3301 | if (chan->sdu_len > chan->imtu) { |
3296 | err = -EMSGSIZE; | 3302 | err = -EMSGSIZE; |
@@ -3783,10 +3789,10 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb) | |||
3783 | goto drop; | 3789 | goto drop; |
3784 | 3790 | ||
3785 | if (__is_sar_start(chan, control) && !__is_sframe(chan, control)) | 3791 | if (__is_sar_start(chan, control) && !__is_sframe(chan, control)) |
3786 | len -= 2; | 3792 | len -= L2CAP_SDULEN_SIZE; |
3787 | 3793 | ||
3788 | if (chan->fcs == L2CAP_FCS_CRC16) | 3794 | if (chan->fcs == L2CAP_FCS_CRC16) |
3789 | len -= 2; | 3795 | len -= L2CAP_FCS_SIZE; |
3790 | 3796 | ||
3791 | if (len > chan->mps) { | 3797 | if (len > chan->mps) { |
3792 | l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); | 3798 | l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); |
@@ -3884,10 +3890,10 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk | |||
3884 | goto drop; | 3890 | goto drop; |
3885 | 3891 | ||
3886 | if (__is_sar_start(chan, control)) | 3892 | if (__is_sar_start(chan, control)) |
3887 | len -= 2; | 3893 | len -= L2CAP_SDULEN_SIZE; |
3888 | 3894 | ||
3889 | if (chan->fcs == L2CAP_FCS_CRC16) | 3895 | if (chan->fcs == L2CAP_FCS_CRC16) |
3890 | len -= 2; | 3896 | len -= L2CAP_FCS_SIZE; |
3891 | 3897 | ||
3892 | if (len > chan->mps || len < 0 || __is_sframe(chan, control)) | 3898 | if (len > chan->mps || len < 0 || __is_sframe(chan, control)) |
3893 | goto drop; | 3899 | goto drop; |