Commit 5e4e3972 authored by Andrei Emeltchenko's avatar Andrei Emeltchenko Committed by Gustavo Padovan

Bluetooth: Refactor l2cap_send_disconn_req

l2cap_send_disconn_req takes 3 parameters of which conn might be
derived from chan. Make this conversion inside l2cap_send_disconn_req.
Signed-off-by: default avatarAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Signed-off-by: default avatarGustavo Padovan <gustavo.padovan@collabora.co.uk>
parent ffa88e02
...@@ -53,8 +53,7 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn, ...@@ -53,8 +53,7 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn,
static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len, static void l2cap_send_cmd(struct l2cap_conn *conn, u8 ident, u8 code, u16 len,
void *data); void *data);
static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data); static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data);
static void l2cap_send_disconn_req(struct l2cap_conn *conn, static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err);
struct l2cap_chan *chan, int err);
static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control, static void l2cap_tx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
struct sk_buff_head *skbs, u8 event); struct sk_buff_head *skbs, u8 event);
...@@ -632,7 +631,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason) ...@@ -632,7 +631,7 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason)
if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED && if (chan->chan_type == L2CAP_CHAN_CONN_ORIENTED &&
conn->hcon->type == ACL_LINK) { conn->hcon->type == ACL_LINK) {
__set_chan_timer(chan, sk->sk_sndtimeo); __set_chan_timer(chan, sk->sk_sndtimeo);
l2cap_send_disconn_req(conn, chan, reason); l2cap_send_disconn_req(chan, reason);
} else } else
l2cap_chan_del(chan, reason); l2cap_chan_del(chan, reason);
break; break;
...@@ -1180,10 +1179,10 @@ static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask) ...@@ -1180,10 +1179,10 @@ static inline int l2cap_mode_supported(__u8 mode, __u32 feat_mask)
} }
} }
static void l2cap_send_disconn_req(struct l2cap_conn *conn, static void l2cap_send_disconn_req(struct l2cap_chan *chan, int err)
struct l2cap_chan *chan, int err)
{ {
struct sock *sk = chan->sk; struct sock *sk = chan->sk;
struct l2cap_conn *conn = chan->conn;
struct l2cap_disconn_req req; struct l2cap_disconn_req req;
if (!conn) if (!conn)
...@@ -1960,7 +1959,7 @@ static void l2cap_ertm_resend(struct l2cap_chan *chan) ...@@ -1960,7 +1959,7 @@ static void l2cap_ertm_resend(struct l2cap_chan *chan)
if (chan->max_tx != 0 && if (chan->max_tx != 0 &&
bt_cb(skb)->control.retries > chan->max_tx) { bt_cb(skb)->control.retries > chan->max_tx) {
BT_DBG("Retry limit exceeded (%d)", chan->max_tx); BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
l2cap_seq_list_clear(&chan->retrans_list); l2cap_seq_list_clear(&chan->retrans_list);
break; break;
} }
...@@ -2666,7 +2665,7 @@ static void l2cap_tx_state_wait_f(struct l2cap_chan *chan, ...@@ -2666,7 +2665,7 @@ static void l2cap_tx_state_wait_f(struct l2cap_chan *chan,
__set_monitor_timer(chan); __set_monitor_timer(chan);
chan->retry_count++; chan->retry_count++;
} else { } else {
l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED); l2cap_send_disconn_req(chan, ECONNABORTED);
} }
break; break;
default: default:
...@@ -3877,7 +3876,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, ...@@ -3877,7 +3876,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
/* Complete config. */ /* Complete config. */
len = l2cap_parse_conf_req(chan, rsp); len = l2cap_parse_conf_req(chan, rsp);
if (len < 0) { if (len < 0) {
l2cap_send_disconn_req(conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
goto unlock; goto unlock;
} }
...@@ -3899,7 +3898,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, ...@@ -3899,7 +3898,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn,
err = l2cap_ertm_init(chan); err = l2cap_ertm_init(chan);
if (err < 0) if (err < 0)
l2cap_send_disconn_req(chan->conn, chan, -err); l2cap_send_disconn_req(chan, -err);
else else
l2cap_chan_ready(chan); l2cap_chan_ready(chan);
...@@ -3967,7 +3966,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, ...@@ -3967,7 +3966,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,
len = l2cap_parse_conf_rsp(chan, rsp->data, len, len = l2cap_parse_conf_rsp(chan, rsp->data, len,
buf, &result); buf, &result);
if (len < 0) { if (len < 0) {
l2cap_send_disconn_req(conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
goto done; goto done;
} }
...@@ -3988,7 +3987,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, ...@@ -3988,7 +3987,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,
char req[64]; char req[64];
if (len > sizeof(req) - sizeof(struct l2cap_conf_req)) { if (len > sizeof(req) - sizeof(struct l2cap_conf_req)) {
l2cap_send_disconn_req(conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
goto done; goto done;
} }
...@@ -3997,7 +3996,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, ...@@ -3997,7 +3996,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,
len = l2cap_parse_conf_rsp(chan, rsp->data, len, len = l2cap_parse_conf_rsp(chan, rsp->data, len,
req, &result); req, &result);
if (len < 0) { if (len < 0) {
l2cap_send_disconn_req(conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
goto done; goto done;
} }
...@@ -4013,7 +4012,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, ...@@ -4013,7 +4012,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,
l2cap_chan_set_err(chan, ECONNRESET); l2cap_chan_set_err(chan, ECONNRESET);
__set_chan_timer(chan, L2CAP_DISC_REJ_TIMEOUT); __set_chan_timer(chan, L2CAP_DISC_REJ_TIMEOUT);
l2cap_send_disconn_req(conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
goto done; goto done;
} }
...@@ -4030,7 +4029,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, ...@@ -4030,7 +4029,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn,
err = l2cap_ertm_init(chan); err = l2cap_ertm_init(chan);
if (err < 0) if (err < 0)
l2cap_send_disconn_req(chan->conn, chan, -err); l2cap_send_disconn_req(chan, -err);
else else
l2cap_chan_ready(chan); l2cap_chan_ready(chan);
} }
...@@ -4392,7 +4391,7 @@ static void l2cap_logical_fail(struct l2cap_chan *chan) ...@@ -4392,7 +4391,7 @@ static void l2cap_logical_fail(struct l2cap_chan *chan)
/* Logical link setup failed */ /* Logical link setup failed */
if (chan->state != BT_CONNECTED) { if (chan->state != BT_CONNECTED) {
/* Create channel failure, disconnect */ /* Create channel failure, disconnect */
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
return; return;
} }
...@@ -4435,7 +4434,7 @@ static void l2cap_logical_finish_create(struct l2cap_chan *chan, ...@@ -4435,7 +4434,7 @@ static void l2cap_logical_finish_create(struct l2cap_chan *chan,
err = l2cap_ertm_init(chan); err = l2cap_ertm_init(chan);
if (err < 0) if (err < 0)
l2cap_send_disconn_req(chan->conn, chan, -err); l2cap_send_disconn_req(chan, -err);
else else
l2cap_chan_ready(chan); l2cap_chan_ready(chan);
} }
...@@ -5400,7 +5399,7 @@ static void l2cap_handle_srej(struct l2cap_chan *chan, ...@@ -5400,7 +5399,7 @@ static void l2cap_handle_srej(struct l2cap_chan *chan,
if (control->reqseq == chan->next_tx_seq) { if (control->reqseq == chan->next_tx_seq) {
BT_DBG("Invalid reqseq %d, disconnecting", control->reqseq); BT_DBG("Invalid reqseq %d, disconnecting", control->reqseq);
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
return; return;
} }
...@@ -5414,7 +5413,7 @@ static void l2cap_handle_srej(struct l2cap_chan *chan, ...@@ -5414,7 +5413,7 @@ static void l2cap_handle_srej(struct l2cap_chan *chan,
if (chan->max_tx != 0 && bt_cb(skb)->control.retries >= chan->max_tx) { if (chan->max_tx != 0 && bt_cb(skb)->control.retries >= chan->max_tx) {
BT_DBG("Retry limit exceeded (%d)", chan->max_tx); BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
return; return;
} }
...@@ -5458,7 +5457,7 @@ static void l2cap_handle_rej(struct l2cap_chan *chan, ...@@ -5458,7 +5457,7 @@ static void l2cap_handle_rej(struct l2cap_chan *chan,
if (control->reqseq == chan->next_tx_seq) { if (control->reqseq == chan->next_tx_seq) {
BT_DBG("Invalid reqseq %d, disconnecting", control->reqseq); BT_DBG("Invalid reqseq %d, disconnecting", control->reqseq);
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
return; return;
} }
...@@ -5467,7 +5466,7 @@ static void l2cap_handle_rej(struct l2cap_chan *chan, ...@@ -5467,7 +5466,7 @@ static void l2cap_handle_rej(struct l2cap_chan *chan,
if (chan->max_tx && skb && if (chan->max_tx && skb &&
bt_cb(skb)->control.retries >= chan->max_tx) { bt_cb(skb)->control.retries >= chan->max_tx) {
BT_DBG("Retry limit exceeded (%d)", chan->max_tx); BT_DBG("Retry limit exceeded (%d)", chan->max_tx);
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
return; return;
} }
...@@ -5651,8 +5650,7 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan, ...@@ -5651,8 +5650,7 @@ static int l2cap_rx_state_recv(struct l2cap_chan *chan,
break; break;
case L2CAP_TXSEQ_INVALID: case L2CAP_TXSEQ_INVALID:
default: default:
l2cap_send_disconn_req(chan->conn, chan, l2cap_send_disconn_req(chan, ECONNRESET);
ECONNRESET);
break; break;
} }
break; break;
...@@ -5785,8 +5783,7 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan, ...@@ -5785,8 +5783,7 @@ static int l2cap_rx_state_srej_sent(struct l2cap_chan *chan,
break; break;
case L2CAP_TXSEQ_INVALID: case L2CAP_TXSEQ_INVALID:
default: default:
l2cap_send_disconn_req(chan->conn, chan, l2cap_send_disconn_req(chan, ECONNRESET);
ECONNRESET);
break; break;
} }
break; break;
...@@ -5981,7 +5978,7 @@ static int l2cap_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control, ...@@ -5981,7 +5978,7 @@ static int l2cap_rx(struct l2cap_chan *chan, struct l2cap_ctrl *control,
BT_DBG("Invalid reqseq %d (next_tx_seq %d, expected_ack_seq %d", BT_DBG("Invalid reqseq %d (next_tx_seq %d, expected_ack_seq %d",
control->reqseq, chan->next_tx_seq, control->reqseq, chan->next_tx_seq,
chan->expected_ack_seq); chan->expected_ack_seq);
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
} }
return err; return err;
...@@ -6050,7 +6047,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) ...@@ -6050,7 +6047,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
len -= L2CAP_FCS_SIZE; 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, ECONNRESET);
goto drop; goto drop;
} }
...@@ -6075,8 +6072,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) ...@@ -6075,8 +6072,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
} }
if (err) if (err)
l2cap_send_disconn_req(chan->conn, chan, l2cap_send_disconn_req(chan, ECONNRESET);
ECONNRESET);
} else { } else {
const u8 rx_func_to_event[4] = { const u8 rx_func_to_event[4] = {
L2CAP_EV_RECV_RR, L2CAP_EV_RECV_REJ, L2CAP_EV_RECV_RR, L2CAP_EV_RECV_REJ,
...@@ -6093,7 +6089,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) ...@@ -6093,7 +6089,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
if (len != 0) { if (len != 0) {
BT_ERR("Trailing bytes: %d in sframe", len); BT_ERR("Trailing bytes: %d in sframe", len);
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
goto drop; goto drop;
} }
...@@ -6104,7 +6100,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb) ...@@ -6104,7 +6100,7 @@ static int l2cap_data_rcv(struct l2cap_chan *chan, struct sk_buff *skb)
event = rx_func_to_event[control->super]; event = rx_func_to_event[control->super];
if (l2cap_rx(chan, control, skb, event)) if (l2cap_rx(chan, control, skb, event))
l2cap_send_disconn_req(chan->conn, chan, ECONNRESET); l2cap_send_disconn_req(chan, ECONNRESET);
} }
return 0; return 0;
......
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