Re: [PATCH -v2 3/7] Bluetooth: Create l2cap_chan_send()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux