Commit 03a51213 authored by Andrei Emeltchenko's avatar Andrei Emeltchenko Committed by Gustavo F. Padovan

Bluetooth: EWS: remove magic numbers in l2cap

Remove magic numbers for FCS, SDU LEN and PSM LEN
when calculating packet payload.
Signed-off-by: default avatarAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
parent 836be934
...@@ -585,7 +585,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control) ...@@ -585,7 +585,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control)
hlen = L2CAP_ENH_HDR_SIZE; hlen = L2CAP_ENH_HDR_SIZE;
if (chan->fcs == L2CAP_FCS_CRC16) if (chan->fcs == L2CAP_FCS_CRC16)
hlen += 2; hlen += L2CAP_FCS_SIZE;
BT_DBG("chan %p, control 0x%8.8x", chan, control); BT_DBG("chan %p, control 0x%8.8x", chan, control);
...@@ -610,8 +610,8 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control) ...@@ -610,8 +610,8 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u32 control)
__put_control(chan, control, skb_put(skb, __ctrl_size(chan))); __put_control(chan, control, skb_put(skb, __ctrl_size(chan)));
if (chan->fcs == L2CAP_FCS_CRC16) { if (chan->fcs == L2CAP_FCS_CRC16) {
u16 fcs = crc16(0, (u8 *)lh, count - 2); u16 fcs = crc16(0, (u8 *)lh, count - L2CAP_FCS_SIZE);
put_unaligned_le16(fcs, skb_put(skb, 2)); put_unaligned_le16(fcs, skb_put(skb, L2CAP_FCS_SIZE));
} }
if (lmp_no_flush_capable(conn->hcon->hdev)) if (lmp_no_flush_capable(conn->hcon->hdev))
...@@ -1289,8 +1289,10 @@ static void l2cap_streaming_send(struct l2cap_chan *chan) ...@@ -1289,8 +1289,10 @@ static void l2cap_streaming_send(struct l2cap_chan *chan)
__put_control(chan, control, skb->data + L2CAP_HDR_SIZE); __put_control(chan, control, skb->data + L2CAP_HDR_SIZE);
if (chan->fcs == L2CAP_FCS_CRC16) { if (chan->fcs == L2CAP_FCS_CRC16) {
fcs = crc16(0, (u8 *)skb->data, skb->len - 2); fcs = crc16(0, (u8 *)skb->data,
put_unaligned_le16(fcs, skb->data + skb->len - 2); skb->len - L2CAP_FCS_SIZE);
put_unaligned_le16(fcs,
skb->data + skb->len - L2CAP_FCS_SIZE);
} }
l2cap_do_send(chan, skb); l2cap_do_send(chan, skb);
...@@ -1339,8 +1341,10 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq) ...@@ -1339,8 +1341,10 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq)
__put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE);
if (chan->fcs == L2CAP_FCS_CRC16) { if (chan->fcs == L2CAP_FCS_CRC16) {
fcs = crc16(0, (u8 *)tx_skb->data, tx_skb->len - 2); fcs = crc16(0, (u8 *)tx_skb->data,
put_unaligned_le16(fcs, tx_skb->data + tx_skb->len - 2); tx_skb->len - L2CAP_FCS_SIZE);
put_unaligned_le16(fcs,
tx_skb->data + tx_skb->len - L2CAP_FCS_SIZE);
} }
l2cap_do_send(chan, tx_skb); l2cap_do_send(chan, tx_skb);
...@@ -1380,8 +1384,10 @@ static int l2cap_ertm_send(struct l2cap_chan *chan) ...@@ -1380,8 +1384,10 @@ static int l2cap_ertm_send(struct l2cap_chan *chan)
__put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE); __put_control(chan, control, tx_skb->data + L2CAP_HDR_SIZE);
if (chan->fcs == L2CAP_FCS_CRC16) { if (chan->fcs == L2CAP_FCS_CRC16) {
fcs = crc16(0, (u8 *)skb->data, tx_skb->len - 2); fcs = crc16(0, (u8 *)skb->data,
put_unaligned_le16(fcs, skb->data + tx_skb->len - 2); tx_skb->len - L2CAP_FCS_SIZE);
put_unaligned_le16(fcs, skb->data +
tx_skb->len - L2CAP_FCS_SIZE);
} }
l2cap_do_send(chan, tx_skb); l2cap_do_send(chan, tx_skb);
...@@ -1491,7 +1497,7 @@ static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct ...@@ -1491,7 +1497,7 @@ static struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct
struct sock *sk = chan->sk; struct sock *sk = chan->sk;
struct l2cap_conn *conn = chan->conn; struct l2cap_conn *conn = chan->conn;
struct sk_buff *skb; struct sk_buff *skb;
int err, count, hlen = L2CAP_HDR_SIZE + 2; int err, count, hlen = L2CAP_HDR_SIZE + L2CAP_PSMLEN_SIZE;
struct l2cap_hdr *lh; struct l2cap_hdr *lh;
BT_DBG("sk %p len %d", sk, (int)len); 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,10 +1572,10 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
hlen = L2CAP_ENH_HDR_SIZE; hlen = L2CAP_ENH_HDR_SIZE;
if (sdulen) if (sdulen)
hlen += 2; hlen += L2CAP_SDULEN_SIZE;
if (chan->fcs == L2CAP_FCS_CRC16) if (chan->fcs == L2CAP_FCS_CRC16)
hlen += 2; hlen += L2CAP_FCS_SIZE;
count = min_t(unsigned int, (conn->mtu - hlen), len); count = min_t(unsigned int, (conn->mtu - hlen), len);
skb = bt_skb_send_alloc(sk, count + hlen, 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,7 +1591,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
__put_control(chan, control, skb_put(skb, __ctrl_size(chan))); __put_control(chan, control, skb_put(skb, __ctrl_size(chan)));
if (sdulen) if (sdulen)
put_unaligned_le16(sdulen, skb_put(skb, 2)); put_unaligned_le16(sdulen, skb_put(skb, L2CAP_SDULEN_SIZE));
err = l2cap_skbuff_fromiovec(sk, msg, len, count, skb); err = l2cap_skbuff_fromiovec(sk, msg, len, count, skb);
if (unlikely(err < 0)) { if (unlikely(err < 0)) {
...@@ -1594,7 +1600,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, ...@@ -1594,7 +1600,7 @@ static struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan,
} }
if (chan->fcs == L2CAP_FCS_CRC16) if (chan->fcs == L2CAP_FCS_CRC16)
put_unaligned_le16(0, skb_put(skb, 2)); put_unaligned_le16(0, skb_put(skb, L2CAP_FCS_SIZE));
bt_cb(skb)->retries = 0; bt_cb(skb)->retries = 0;
return skb; return skb;
...@@ -3180,7 +3186,7 @@ static int l2cap_check_fcs(struct l2cap_chan *chan, struct sk_buff *skb) ...@@ -3180,7 +3186,7 @@ static int l2cap_check_fcs(struct l2cap_chan *chan, struct sk_buff *skb)
hdr_size = L2CAP_ENH_HDR_SIZE; hdr_size = L2CAP_ENH_HDR_SIZE;
if (chan->fcs == L2CAP_FCS_CRC16) { if (chan->fcs == L2CAP_FCS_CRC16) {
skb_trim(skb, skb->len - 2); skb_trim(skb, skb->len - L2CAP_FCS_SIZE);
rcv_fcs = get_unaligned_le16(skb->data + skb->len); rcv_fcs = get_unaligned_le16(skb->data + skb->len);
our_fcs = crc16(0, skb->data - hdr_size, skb->len + hdr_size); our_fcs = crc16(0, skb->data - hdr_size, skb->len + hdr_size);
...@@ -3290,7 +3296,7 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u3 ...@@ -3290,7 +3296,7 @@ static int l2cap_reassemble_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u3
break; break;
chan->sdu_len = get_unaligned_le16(skb->data); chan->sdu_len = get_unaligned_le16(skb->data);
skb_pull(skb, 2); skb_pull(skb, L2CAP_SDULEN_SIZE);
if (chan->sdu_len > chan->imtu) { if (chan->sdu_len > chan->imtu) {
err = -EMSGSIZE; err = -EMSGSIZE;
...@@ -3783,10 +3789,10 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb) ...@@ -3783,10 +3789,10 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
goto drop; goto drop;
if (__is_sar_start(chan, control) && !__is_sframe(chan, control)) if (__is_sar_start(chan, control) && !__is_sframe(chan, control))
len -= 2; len -= L2CAP_SDULEN_SIZE;
if (chan->fcs == L2CAP_FCS_CRC16) if (chan->fcs == L2CAP_FCS_CRC16)
len -= 2; len -= L2CAP_FCS_SIZE;
if (len > chan->mps) { if (len > chan->mps) {
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); 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,10 +3890,10 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
goto drop; goto drop;
if (__is_sar_start(chan, control)) if (__is_sar_start(chan, control))
len -= 2; len -= L2CAP_SDULEN_SIZE;
if (chan->fcs == L2CAP_FCS_CRC16) if (chan->fcs == L2CAP_FCS_CRC16)
len -= 2; len -= L2CAP_FCS_SIZE;
if (len > chan->mps || len < 0 || __is_sframe(chan, control)) if (len > chan->mps || len < 0 || __is_sframe(chan, control))
goto drop; goto drop;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment