Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9b27f350 authored by Andrei Emeltchenko's avatar Andrei Emeltchenko Committed by Johan Hedberg
Browse files

Bluetooth: Remove duplicated code in l2cap conn req



The same sequence sending L2CAP Connection Request was used in several
places. Using subroutine makes those places easy to read.

Signed-off-by: default avatarAndrei Emeltchenko <andrei.emeltchenko@intel.com>
Reviewed-by: default avatarUlisses Furquim <ulisses@profusion.mobi>
Acked-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
parent 5b4cedaa
Loading
Loading
Loading
Loading
+19 −30
Original line number Original line Diff line number Diff line
@@ -667,26 +667,32 @@ static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan)
	return !test_bit(CONF_CONNECT_PEND, &chan->conf_state);
	return !test_bit(CONF_CONNECT_PEND, &chan->conf_state);
}
}


static void l2cap_do_start(struct l2cap_chan *chan)
static void l2cap_send_conn_req(struct l2cap_chan *chan)
{
{
	struct l2cap_conn *conn = chan->conn;
	struct l2cap_conn *conn = chan->conn;

	if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT) {
		if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE))
			return;

		if (l2cap_chan_check_security(chan) &&
				__l2cap_no_conn_pending(chan)) {
	struct l2cap_conn_req req;
	struct l2cap_conn_req req;

	req.scid = cpu_to_le16(chan->scid);
	req.scid = cpu_to_le16(chan->scid);
	req.psm  = chan->psm;
	req.psm  = chan->psm;


	chan->ident = l2cap_get_ident(conn);
	chan->ident = l2cap_get_ident(conn);

	set_bit(CONF_CONNECT_PEND, &chan->conf_state);
	set_bit(CONF_CONNECT_PEND, &chan->conf_state);


			l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_REQ,
	l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_REQ, sizeof(req), &req);
							sizeof(req), &req);
}
}

static void l2cap_do_start(struct l2cap_chan *chan)
{
	struct l2cap_conn *conn = chan->conn;

	if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT) {
		if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE))
			return;

		if (l2cap_chan_check_security(chan) &&
				__l2cap_no_conn_pending(chan))
			l2cap_send_conn_req(chan);
	} else {
	} else {
		struct l2cap_info_req req;
		struct l2cap_info_req req;
		req.type = cpu_to_le16(L2CAP_IT_FEAT_MASK);
		req.type = cpu_to_le16(L2CAP_IT_FEAT_MASK);
@@ -763,8 +769,6 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
		}
		}


		if (chan->state == BT_CONNECT) {
		if (chan->state == BT_CONNECT) {
			struct l2cap_conn_req req;

			if (!l2cap_chan_check_security(chan) ||
			if (!l2cap_chan_check_security(chan) ||
					!__l2cap_no_conn_pending(chan)) {
					!__l2cap_no_conn_pending(chan)) {
				l2cap_chan_unlock(chan);
				l2cap_chan_unlock(chan);
@@ -779,14 +783,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
				continue;
				continue;
			}
			}


			req.scid = cpu_to_le16(chan->scid);
			l2cap_send_conn_req(chan);
			req.psm  = chan->psm;

			chan->ident = l2cap_get_ident(conn);
			set_bit(CONF_CONNECT_PEND, &chan->conf_state);

			l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_REQ,
							sizeof(req), &req);


		} else if (chan->state == BT_CONNECT2) {
		} else if (chan->state == BT_CONNECT2) {
			struct l2cap_conn_rsp rsp;
			struct l2cap_conn_rsp rsp;
@@ -4593,15 +4590,7 @@ int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)


		if (chan->state == BT_CONNECT) {
		if (chan->state == BT_CONNECT) {
			if (!status) {
			if (!status) {
				struct l2cap_conn_req req;
				l2cap_send_conn_req(chan);
				req.scid = cpu_to_le16(chan->scid);
				req.psm  = chan->psm;

				chan->ident = l2cap_get_ident(conn);
				set_bit(CONF_CONNECT_PEND, &chan->conf_state);

				l2cap_send_cmd(conn, chan->ident,
					L2CAP_CONN_REQ, sizeof(req), &req);
			} else {
			} else {
				__clear_chan_timer(chan);
				__clear_chan_timer(chan);
				__set_chan_timer(chan,
				__set_chan_timer(chan,