Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: "Gustavo F. Padovan" <padovan@profusion.mobi>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH -v2 3/7] Bluetooth: Create l2cap_chan_send()
Date: Mon, 16 May 2011 11:07:25 +0200	[thread overview]
Message-ID: <201105161107.25986.szymon.janc@tieto.com> (raw)
In-Reply-To: <1305314450-25493-4-git-send-email-padovan@profusion.mobi>

Hi,

> This move all the sending logic to l2cap_core.c, but we still have a
> socket dependence there, struct msghdr. It will be removed in some of the
> further commits.

> +int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
> +{
> +	struct sock *sk = chan->sk;
> +	struct sk_buff *skb;
> +	u16 control;
> +	int err;
> +
> +	/* Connectionless channel */
> +	if (sk->sk_type == SOCK_DGRAM) {
> +		skb = l2cap_create_connless_pdu(chan, msg, len);
> +		if (IS_ERR(skb))
> +			return PTR_ERR(skb);
> +
> +		l2cap_do_send(chan, skb);
> +		return len;
> +	}
> +
> +	switch (chan->mode) {
> +	case L2CAP_MODE_BASIC:
> +		/* Check outgoing MTU */
> +		if (len > chan->omtu)
> +			return -EMSGSIZE;
> +
> +		/* Create a basic PDU */
> +		skb = l2cap_create_basic_pdu(chan, msg, len);
> +		if (IS_ERR(skb))
> +			return PTR_ERR(skb);
> +
> +		l2cap_do_send(chan, skb);
> +		err = len;
> +		break;
> +
> +	case L2CAP_MODE_ERTM:
> +	case L2CAP_MODE_STREAMING:

How about moving common part (sdu if-else) to a function and separate those 2 cases?
Would be less confusing imho.

> +		/* Entire SDU fits into one PDU */
> +		if (len <= chan->remote_mps) {
> +			control = L2CAP_SDU_UNSEGMENTED;
> +			skb = l2cap_create_iframe_pdu(chan, msg, len, control,
> +									0);
> +			if (IS_ERR(skb))
> +				return PTR_ERR(skb);
> +
> +			__skb_queue_tail(&chan->tx_q, skb);
> +
> +			if (chan->tx_send_head == NULL)
> +				chan->tx_send_head = skb;
> +
> +		} else {
> +			/* Segment SDU into multiples PDUs */
> +			err = l2cap_sar_segment_sdu(chan, msg, len);
> +			if (err < 0)
> +				return err;
> +		}
> +
> +		if (chan->mode == L2CAP_MODE_STREAMING) {
> +			l2cap_streaming_send(chan);
> +			err = len;
> +			break;
> +		}
> +
> +		if ((chan->conn_state & L2CAP_CONN_REMOTE_BUSY) &&
> +				(chan->conn_state & L2CAP_CONN_WAIT_F)) {
> +			err = len;
> +			break;
> +		}
> +
> +		err = l2cap_ertm_send(chan);
> +		if (err >= 0)
> +			err = len;
> +
> +		break;
> +
> +	default:
> +		BT_DBG("bad state %1.1x", chan->mode);
> +		err = -EBADFD;
> +	}
> +
> +	return err;
> +}

-- 
BR
Szymon Janc

      parent reply	other threads:[~2011-05-16  9:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-13 19:20 [PATCH -v2 0/7] L2CAP rework patches Gustavo F. Padovan
2011-05-13 19:20 ` [PATCH -v2 1/7] Bluetooth: Remove leftover debug messages Gustavo F. Padovan
2011-05-13 19:20   ` [PATCH -v2 2/7] Bluetooth: Create __l2cap_chan_close() Gustavo F. Padovan
2011-05-13 19:20     ` [PATCH -v2 3/7] Bluetooth: Create l2cap_chan_send() Gustavo F. Padovan
2011-05-13 19:20       ` [PATCH -v2 4/7] Bluetooth: Add chan->chan_type struct member Gustavo F. Padovan
2011-05-13 19:20         ` [PATCH -v2 5/7] Bluetooth: create channel timer to replace sk_timer Gustavo F. Padovan
2011-05-13 19:20           ` [PATCH -v2 6/7] Bluetooth: Remove export of l2cap_chan_clear_timer() Gustavo F. Padovan
2011-05-13 19:20             ` [PATCH -v2 7/7] Bluetooth: Rename __l2cap_chan_close() to l2cap_chan_close() Gustavo F. Padovan
2011-05-16  9:07       ` Szymon Janc [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201105161107.25986.szymon.janc@tieto.com \
    --to=szymon.janc@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=padovan@profusion.mobi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox