aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/l2cap.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/bluetooth/l2cap.c')
-rw-r--r--net/bluetooth/l2cap.c110
1 files changed, 85 insertions, 25 deletions
diff --git a/net/bluetooth/l2cap.c b/net/bluetooth/l2cap.c
index 54992f782301..5129b88c8e5b 100644
--- a/net/bluetooth/l2cap.c
+++ b/net/bluetooth/l2cap.c
@@ -54,6 +54,7 @@
54#define VERSION "2.14" 54#define VERSION "2.14"
55 55
56static int enable_ertm = 0; 56static int enable_ertm = 0;
57static int max_transmit = L2CAP_DEFAULT_MAX_TX;
57 58
58static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN; 59static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN;
59static u8 l2cap_fixed_chan[8] = { 0x02, }; 60static u8 l2cap_fixed_chan[8] = { 0x02, };
@@ -373,6 +374,8 @@ static inline int l2cap_send_rr_or_rnr(struct l2cap_pinfo *pi, u16 control)
373 else 374 else
374 control |= L2CAP_SUPER_RCV_READY; 375 control |= L2CAP_SUPER_RCV_READY;
375 376
377 control |= pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT;
378
376 return l2cap_send_sframe(pi, control); 379 return l2cap_send_sframe(pi, control);
377} 380}
378 381
@@ -1333,7 +1336,7 @@ static int l2cap_retransmit_frame(struct sock *sk, u8 tx_seq)
1333 tx_skb = skb_clone(skb, GFP_ATOMIC); 1336 tx_skb = skb_clone(skb, GFP_ATOMIC);
1334 bt_cb(skb)->retries++; 1337 bt_cb(skb)->retries++;
1335 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); 1338 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
1336 control |= (pi->req_seq << L2CAP_CTRL_REQSEQ_SHIFT) 1339 control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
1337 | (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); 1340 | (tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
1338 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE); 1341 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
1339 1342
@@ -1375,7 +1378,7 @@ static int l2cap_ertm_send(struct sock *sk)
1375 bt_cb(skb)->retries++; 1378 bt_cb(skb)->retries++;
1376 1379
1377 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE); 1380 control = get_unaligned_le16(tx_skb->data + L2CAP_HDR_SIZE);
1378 control |= (pi->req_seq << L2CAP_CTRL_REQSEQ_SHIFT) 1381 control |= (pi->buffer_seq << L2CAP_CTRL_REQSEQ_SHIFT)
1379 | (pi->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT); 1382 | (pi->next_tx_seq << L2CAP_CTRL_TXSEQ_SHIFT);
1380 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE); 1383 put_unaligned_le16(control, tx_skb->data + L2CAP_HDR_SIZE);
1381 1384
@@ -2173,6 +2176,21 @@ static void l2cap_add_conf_opt(void **ptr, u8 type, u8 len, unsigned long val)
2173 *ptr += L2CAP_CONF_OPT_SIZE + len; 2176 *ptr += L2CAP_CONF_OPT_SIZE + len;
2174} 2177}
2175 2178
2179static inline void l2cap_ertm_init(struct sock *sk)
2180{
2181 l2cap_pi(sk)->expected_ack_seq = 0;
2182 l2cap_pi(sk)->unacked_frames = 0;
2183 l2cap_pi(sk)->buffer_seq = 0;
2184 l2cap_pi(sk)->num_to_ack = 0;
2185
2186 setup_timer(&l2cap_pi(sk)->retrans_timer,
2187 l2cap_retrans_timeout, (unsigned long) sk);
2188 setup_timer(&l2cap_pi(sk)->monitor_timer,
2189 l2cap_monitor_timeout, (unsigned long) sk);
2190
2191 __skb_queue_head_init(SREJ_QUEUE(sk));
2192}
2193
2176static int l2cap_mode_supported(__u8 mode, __u32 feat_mask) 2194static int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
2177{ 2195{
2178 u32 local_feat_mask = l2cap_feat_mask; 2196 u32 local_feat_mask = l2cap_feat_mask;
@@ -2236,7 +2254,7 @@ done:
2236 case L2CAP_MODE_ERTM: 2254 case L2CAP_MODE_ERTM:
2237 rfc.mode = L2CAP_MODE_ERTM; 2255 rfc.mode = L2CAP_MODE_ERTM;
2238 rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW; 2256 rfc.txwin_size = L2CAP_DEFAULT_TX_WINDOW;
2239 rfc.max_transmit = L2CAP_DEFAULT_MAX_TX; 2257 rfc.max_transmit = max_transmit;
2240 rfc.retrans_timeout = 0; 2258 rfc.retrans_timeout = 0;
2241 rfc.monitor_timeout = 0; 2259 rfc.monitor_timeout = 0;
2242 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE); 2260 rfc.max_pdu_size = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
@@ -2761,17 +2779,13 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
2761 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16; 2779 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16;
2762 2780
2763 sk->sk_state = BT_CONNECTED; 2781 sk->sk_state = BT_CONNECTED;
2764 l2cap_pi(sk)->next_tx_seq = 0;
2765 l2cap_pi(sk)->expected_ack_seq = 0;
2766 l2cap_pi(sk)->unacked_frames = 0;
2767
2768 setup_timer(&l2cap_pi(sk)->retrans_timer,
2769 l2cap_retrans_timeout, (unsigned long) sk);
2770 setup_timer(&l2cap_pi(sk)->monitor_timer,
2771 l2cap_monitor_timeout, (unsigned long) sk);
2772 2782
2783 l2cap_pi(sk)->next_tx_seq = 0;
2784 l2cap_pi(sk)->expected_tx_seq = 0;
2773 __skb_queue_head_init(TX_QUEUE(sk)); 2785 __skb_queue_head_init(TX_QUEUE(sk));
2774 __skb_queue_head_init(SREJ_QUEUE(sk)); 2786 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM)
2787 l2cap_ertm_init(sk);
2788
2775 l2cap_chan_ready(sk); 2789 l2cap_chan_ready(sk);
2776 goto unlock; 2790 goto unlock;
2777 } 2791 }
@@ -2850,11 +2864,12 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
2850 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16; 2864 l2cap_pi(sk)->fcs = L2CAP_FCS_CRC16;
2851 2865
2852 sk->sk_state = BT_CONNECTED; 2866 sk->sk_state = BT_CONNECTED;
2867 l2cap_pi(sk)->next_tx_seq = 0;
2853 l2cap_pi(sk)->expected_tx_seq = 0; 2868 l2cap_pi(sk)->expected_tx_seq = 0;
2854 l2cap_pi(sk)->buffer_seq = 0;
2855 l2cap_pi(sk)->num_to_ack = 0;
2856 __skb_queue_head_init(TX_QUEUE(sk)); 2869 __skb_queue_head_init(TX_QUEUE(sk));
2857 __skb_queue_head_init(SREJ_QUEUE(sk)); 2870 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM)
2871 l2cap_ertm_init(sk);
2872
2858 l2cap_chan_ready(sk); 2873 l2cap_chan_ready(sk);
2859 } 2874 }
2860 2875
@@ -2886,9 +2901,12 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd
2886 sk->sk_shutdown = SHUTDOWN_MASK; 2901 sk->sk_shutdown = SHUTDOWN_MASK;
2887 2902
2888 skb_queue_purge(TX_QUEUE(sk)); 2903 skb_queue_purge(TX_QUEUE(sk));
2889 skb_queue_purge(SREJ_QUEUE(sk)); 2904
2890 del_timer(&l2cap_pi(sk)->retrans_timer); 2905 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) {
2891 del_timer(&l2cap_pi(sk)->monitor_timer); 2906 skb_queue_purge(SREJ_QUEUE(sk));
2907 del_timer(&l2cap_pi(sk)->retrans_timer);
2908 del_timer(&l2cap_pi(sk)->monitor_timer);
2909 }
2892 2910
2893 l2cap_chan_del(sk, ECONNRESET); 2911 l2cap_chan_del(sk, ECONNRESET);
2894 bh_unlock_sock(sk); 2912 bh_unlock_sock(sk);
@@ -2913,9 +2931,12 @@ static inline int l2cap_disconnect_rsp(struct l2cap_conn *conn, struct l2cap_cmd
2913 return 0; 2931 return 0;
2914 2932
2915 skb_queue_purge(TX_QUEUE(sk)); 2933 skb_queue_purge(TX_QUEUE(sk));
2916 skb_queue_purge(SREJ_QUEUE(sk)); 2934
2917 del_timer(&l2cap_pi(sk)->retrans_timer); 2935 if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) {
2918 del_timer(&l2cap_pi(sk)->monitor_timer); 2936 skb_queue_purge(SREJ_QUEUE(sk));
2937 del_timer(&l2cap_pi(sk)->retrans_timer);
2938 del_timer(&l2cap_pi(sk)->monitor_timer);
2939 }
2919 2940
2920 l2cap_chan_del(sk, 0); 2941 l2cap_chan_del(sk, 0);
2921 bh_unlock_sock(sk); 2942 bh_unlock_sock(sk);
@@ -3280,12 +3301,16 @@ static inline int l2cap_data_channel_iframe(struct sock *sk, u16 rx_control, str
3280{ 3301{
3281 struct l2cap_pinfo *pi = l2cap_pi(sk); 3302 struct l2cap_pinfo *pi = l2cap_pi(sk);
3282 u8 tx_seq = __get_txseq(rx_control); 3303 u8 tx_seq = __get_txseq(rx_control);
3304 u8 req_seq = __get_reqseq(rx_control);
3283 u16 tx_control = 0; 3305 u16 tx_control = 0;
3284 u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT; 3306 u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT;
3285 int err = 0; 3307 int err = 0;
3286 3308
3287 BT_DBG("sk %p rx_control 0x%4.4x len %d", sk, rx_control, skb->len); 3309 BT_DBG("sk %p rx_control 0x%4.4x len %d", sk, rx_control, skb->len);
3288 3310
3311 pi->expected_ack_seq = req_seq;
3312 l2cap_drop_acked_frames(sk);
3313
3289 if (tx_seq == pi->expected_tx_seq) 3314 if (tx_seq == pi->expected_tx_seq)
3290 goto expected; 3315 goto expected;
3291 3316
@@ -3340,6 +3365,16 @@ expected:
3340 return 0; 3365 return 0;
3341 } 3366 }
3342 3367
3368 if (rx_control & L2CAP_CTRL_FINAL) {
3369 if (pi->conn_state & L2CAP_CONN_REJ_ACT)
3370 pi->conn_state &= ~L2CAP_CONN_REJ_ACT;
3371 else {
3372 sk->sk_send_head = TX_QUEUE(sk)->next;
3373 pi->next_tx_seq = pi->expected_ack_seq;
3374 l2cap_ertm_send(sk);
3375 }
3376 }
3377
3343 pi->buffer_seq = (pi->buffer_seq + 1) % 64; 3378 pi->buffer_seq = (pi->buffer_seq + 1) % 64;
3344 3379
3345 err = l2cap_sar_reassembly_sdu(sk, skb, rx_control); 3380 err = l2cap_sar_reassembly_sdu(sk, skb, rx_control);
@@ -3376,6 +3411,14 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3376 pi->expected_ack_seq = tx_seq; 3411 pi->expected_ack_seq = tx_seq;
3377 l2cap_drop_acked_frames(sk); 3412 l2cap_drop_acked_frames(sk);
3378 3413
3414 if (pi->conn_state & L2CAP_CONN_REJ_ACT)
3415 pi->conn_state &= ~L2CAP_CONN_REJ_ACT;
3416 else {
3417 sk->sk_send_head = TX_QUEUE(sk)->next;
3418 pi->next_tx_seq = pi->expected_ack_seq;
3419 l2cap_ertm_send(sk);
3420 }
3421
3379 if (!(pi->conn_state & L2CAP_CONN_WAIT_F)) 3422 if (!(pi->conn_state & L2CAP_CONN_WAIT_F))
3380 break; 3423 break;
3381 3424
@@ -3403,10 +3446,24 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3403 pi->expected_ack_seq = __get_reqseq(rx_control); 3446 pi->expected_ack_seq = __get_reqseq(rx_control);
3404 l2cap_drop_acked_frames(sk); 3447 l2cap_drop_acked_frames(sk);
3405 3448
3406 sk->sk_send_head = TX_QUEUE(sk)->next; 3449 if (rx_control & L2CAP_CTRL_FINAL) {
3407 pi->next_tx_seq = pi->expected_ack_seq; 3450 if (pi->conn_state & L2CAP_CONN_REJ_ACT)
3451 pi->conn_state &= ~L2CAP_CONN_REJ_ACT;
3452 else {
3453 sk->sk_send_head = TX_QUEUE(sk)->next;
3454 pi->next_tx_seq = pi->expected_ack_seq;
3455 l2cap_ertm_send(sk);
3456 }
3457 } else {
3458 sk->sk_send_head = TX_QUEUE(sk)->next;
3459 pi->next_tx_seq = pi->expected_ack_seq;
3460 l2cap_ertm_send(sk);
3408 3461
3409 l2cap_ertm_send(sk); 3462 if (pi->conn_state & L2CAP_CONN_WAIT_F) {
3463 pi->srej_save_reqseq = tx_seq;
3464 pi->conn_state |= L2CAP_CONN_REJ_ACT;
3465 }
3466 }
3410 3467
3411 break; 3468 break;
3412 3469
@@ -3425,7 +3482,7 @@ static inline int l2cap_data_channel_sframe(struct sock *sk, u16 rx_control, str
3425 } else if (rx_control & L2CAP_CTRL_FINAL) { 3482 } else if (rx_control & L2CAP_CTRL_FINAL) {
3426 if ((pi->conn_state & L2CAP_CONN_SREJ_ACT) && 3483 if ((pi->conn_state & L2CAP_CONN_SREJ_ACT) &&
3427 pi->srej_save_reqseq == tx_seq) 3484 pi->srej_save_reqseq == tx_seq)
3428 pi->srej_save_reqseq &= ~L2CAP_CONN_SREJ_ACT; 3485 pi->conn_state &= ~L2CAP_CONN_SREJ_ACT;
3429 else 3486 else
3430 l2cap_retransmit_frame(sk, tx_seq); 3487 l2cap_retransmit_frame(sk, tx_seq);
3431 } 3488 }
@@ -4004,6 +4061,9 @@ module_exit(l2cap_exit);
4004module_param(enable_ertm, bool, 0644); 4061module_param(enable_ertm, bool, 0644);
4005MODULE_PARM_DESC(enable_ertm, "Enable enhanced retransmission mode"); 4062MODULE_PARM_DESC(enable_ertm, "Enable enhanced retransmission mode");
4006 4063
4064module_param(max_transmit, uint, 0644);
4065MODULE_PARM_DESC(max_transmit, "Max transmit value (default = 3)");
4066
4007MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); 4067MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
4008MODULE_DESCRIPTION("Bluetooth L2CAP ver " VERSION); 4068MODULE_DESCRIPTION("Bluetooth L2CAP ver " VERSION);
4009MODULE_VERSION(VERSION); 4069MODULE_VERSION(VERSION);