Skip to content

Commit fb45de7

Browse files
finikorgGustavo F. Padovan
authored andcommitted
Bluetooth: EWS: rewrite L2CAP ERTM txseq calculation
L2CAP ERTM txseq calculation uses now information about control field type. Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
1 parent 0b209fa commit fb45de7

2 files changed

Lines changed: 38 additions & 20 deletions

File tree

‎include/net/bluetooth/l2cap.h‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ struct l2cap_conn_param_update_rsp {
316316

317317
/* ----- L2CAP channels and connections ----- */
318318
struct srej_list {
319-
__u8 tx_seq;
319+
__u16 tx_seq;
320320
struct list_head list;
321321
};
322322

@@ -362,14 +362,14 @@ struct l2cap_chan {
362362
unsigned long conn_state;
363363
unsigned long flags;
364364

365-
__u8 next_tx_seq;
366-
__u8 expected_ack_seq;
367-
__u8 expected_tx_seq;
368-
__u8 buffer_seq_srej;
369-
__u8 srej_save_reqseq;
370-
__u8 frames_sent;
371-
__u8 unacked_frames;
365+
__u16 next_tx_seq;
366+
__u16 expected_ack_seq;
367+
__u16 expected_tx_seq;
372368
__u16 buffer_seq;
369+
__u16 buffer_seq_srej;
370+
__u16 srej_save_reqseq;
371+
__u16 frames_sent;
372+
__u16 unacked_frames;
373373
__u8 retry_count;
374374
__u8 num_acked;
375375
__u16 sdu_len;
@@ -529,7 +529,25 @@ static inline __u32 __set_reqseq(struct l2cap_chan *chan, __u32 reqseq)
529529
else
530530
return (reqseq << L2CAP_CTRL_REQSEQ_SHIFT) & L2CAP_CTRL_REQSEQ;
531531
}
532-
#define __get_txseq(ctrl) (((ctrl) & L2CAP_CTRL_TXSEQ) >> 1)
532+
533+
static inline __u16 __get_txseq(struct l2cap_chan *chan, __u32 ctrl)
534+
{
535+
if (test_bit(FLAG_EXT_CTRL, &chan->flags))
536+
return (ctrl & L2CAP_EXT_CTRL_TXSEQ) >>
537+
L2CAP_EXT_CTRL_TXSEQ_SHIFT;
538+
else
539+
return (ctrl & L2CAP_CTRL_TXSEQ) >> L2CAP_CTRL_TXSEQ_SHIFT;
540+
}
541+
542+
static inline __u32 __set_txseq(struct l2cap_chan *chan, __u32 txseq)
543+
{
544+
if (test_bit(FLAG_EXT_CTRL, &chan->flags))
545+
return (txseq << L2CAP_EXT_CTRL_TXSEQ_SHIFT) &
546+
L2CAP_EXT_CTRL_TXSEQ;
547+
else
548+
return (txseq << L2CAP_CTRL_TXSEQ_SHIFT) & L2CAP_CTRL_TXSEQ;
549+
}
550+
533551
#define __is_iframe(ctrl) (!((ctrl) & L2CAP_CTRL_FRAME_TYPE))
534552
#define __is_sframe(ctrl) ((ctrl) & L2CAP_CTRL_FRAME_TYPE)
535553
static inline __u8 __get_ctrl_sar(struct l2cap_chan *chan, __u32 ctrl)

‎net/bluetooth/l2cap_core.c‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ static void l2cap_streaming_send(struct l2cap_chan *chan)
12701270

12711271
while ((skb = skb_dequeue(&chan->tx_q))) {
12721272
control = get_unaligned_le16(skb->data + L2CAP_HDR_SIZE);
1273-
control |= chan->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT;
1273+
control |= __set_txseq(chan, chan->next_tx_seq);
12741274
put_unaligned_le16(control, skb->data + L2CAP_HDR_SIZE);
12751275

12761276
if (chan->fcs == L2CAP_FCS_CRC16) {
@@ -1284,7 +1284,7 @@ static void l2cap_streaming_send(struct l2cap_chan *chan)
12841284
}
12851285
}
12861286

1287-
static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq)
1287+
static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u16 tx_seq)
12881288
{
12891289
struct sk_buff *skb, *tx_skb;
12901290
u16 control, fcs;
@@ -1317,7 +1317,7 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq)
13171317
control |= L2CAP_CTRL_FINAL;
13181318

13191319
control |= __set_reqseq(chan, chan->buffer_seq);
1320-
control |= tx_seq << L2CAP_CTRL_TXSEQ_SHIFT;
1320+
control |= __set_txseq(chan, tx_seq);
13211321

13221322
put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
13231323

@@ -1357,7 +1357,7 @@ static int l2cap_ertm_send(struct l2cap_chan *chan)
13571357
control |= L2CAP_CTRL_FINAL;
13581358

13591359
control |= __set_reqseq(chan, chan->buffer_seq);
1360-
control |= chan->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT;
1360+
control |= __set_txseq(chan, chan->next_tx_seq);
13611361
put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
13621362

13631363

@@ -3136,7 +3136,7 @@ static inline void l2cap_send_i_or_rr_or_rnr(struct l2cap_chan *chan)
31363136
}
31373137
}
31383138

3139-
static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb, u8 tx_seq, u8 sar)
3139+
static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb, u16 tx_seq, u8 sar)
31403140
{
31413141
struct sk_buff *next_skb;
31423142
int tx_seq_offset, next_tx_seq_offset;
@@ -3330,7 +3330,7 @@ void l2cap_chan_busy(struct l2cap_chan *chan, int busy)
33303330
}
33313331
}
33323332

3333-
static void l2cap_check_srej_gap(struct l2cap_chan *chan, u8 tx_seq)
3333+
static void l2cap_check_srej_gap(struct l2cap_chan *chan, u16 tx_seq)
33343334
{
33353335
struct sk_buff *skb;
33363336
u16 control;
@@ -3357,7 +3357,7 @@ static void l2cap_check_srej_gap(struct l2cap_chan *chan, u8 tx_seq)
33573357
}
33583358
}
33593359

3360-
static void l2cap_resend_srejframe(struct l2cap_chan *chan, u8 tx_seq)
3360+
static void l2cap_resend_srejframe(struct l2cap_chan *chan, u16 tx_seq)
33613361
{
33623362
struct srej_list *l, *tmp;
33633363
u16 control;
@@ -3376,7 +3376,7 @@ static void l2cap_resend_srejframe(struct l2cap_chan *chan, u8 tx_seq)
33763376
}
33773377
}
33783378

3379-
static void l2cap_send_srejframe(struct l2cap_chan *chan, u8 tx_seq)
3379+
static void l2cap_send_srejframe(struct l2cap_chan *chan, u16 tx_seq)
33803380
{
33813381
struct srej_list *new;
33823382
u16 control;
@@ -3396,7 +3396,7 @@ static void l2cap_send_srejframe(struct l2cap_chan *chan, u8 tx_seq)
33963396

33973397
static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_control, struct sk_buff *skb)
33983398
{
3399-
u8 tx_seq = __get_txseq(rx_control);
3399+
u16 tx_seq = __get_txseq(chan, rx_control);
34003400
u16 req_seq = __get_reqseq(chan, rx_control);
34013401
u8 sar = __get_ctrl_sar(chan, rx_control);
34023402
int tx_seq_offset, expected_tx_seq_offset;
@@ -3763,7 +3763,7 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
37633763
struct l2cap_chan *chan;
37643764
struct sock *sk = NULL;
37653765
u16 control;
3766-
u8 tx_seq;
3766+
u16 tx_seq;
37673767
int len;
37683768

37693769
chan = l2cap_get_chan_by_scid(conn, cid);
@@ -3820,7 +3820,7 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
38203820
if (len > chan->mps || len < 0 || __is_sframe(control))
38213821
goto drop;
38223822

3823-
tx_seq = __get_txseq(control);
3823+
tx_seq = __get_txseq(chan, control);
38243824

38253825
if (chan->expected_tx_seq != tx_seq) {
38263826
/* Frame(s) missing - must discard partial SDU */

0 commit comments

Comments
 (0)