From: Marcel Holtmann <marcel@holtmann.org>
To: Jeremy Cline <jeremy@jcline.org>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [RFC] Bluetooth: Add new serdev based driver for 3-Wire attached controllers
Date: Sun, 18 Mar 2018 20:35:57 +0100 [thread overview]
Message-ID: <71DBC780-64EE-43C9-83E7-4B2F58249EF3@holtmann.org> (raw)
In-Reply-To: <010001623a5a3d47-9a205d5b-5d17-44ed-9cc1-99f3f1448a07-000000@email.amazonses.com>
Hi Jeremy,
>> +static int bt3wire_receive_buf(struct serdev_device *serdev, const u8 *buf,
>> + size_t count)
>> +{
>> + struct bt3wire_dev *bdev = serdev_device_get_drvdata(serdev);
>> + size_t i;
>> +
>> + for (i = 0; i < count; i++) {
>> + const unsigned char *ptr = buf + i;
>> +
>> + switch (bdev->rx_slip_state) {
>> + case SLIP_WAIT_DELIM:
>> + /* The delimiter octet 0xC0 is placed at the start and
>> + * end of every packet. To synchronize with the packet
>> + * stream, wait for the delimiter octet and drop any
>> + * other octets.
>> + */
>> + if (*ptr == SLIP_DELIM) {
>> + bdev->rx_skb = bt_skb_alloc(MAX_PACKET_SIZE,
>> + GFP_ATOMIC);
>> + if (bdev->rx_skb)
>> + bdev->rx_slip_state = SLIP_PACKET;
>> + }
>> + break;
>> + case SLIP_PACKET:
>> + /* Receiving the delimiter octet 0xC0 indicates a
>> + * complete packet, the escape octet 0xDB indicates
>> + * the switch to an escape sequence, and all other
>> + * octets are copied into the result.
>> + */
>> + if (*ptr == SLIP_DELIM) {
>> + bt3wire_process_pkt(bdev, bdev->rx_skb);
>> + bdev->rx_skb = NULL;
>> + bdev->rx_slip_state = SLIP_WAIT_DELIM;
>> + } else if (*ptr == SLIP_ESC) {
>> + bdev->rx_slip_state = SLIP_ESCAPE;
>> + } else {
>> + if (bdev->rx_skb->len < MAX_PACKET_SIZE) {
>> + skb_put_u8(bdev->rx_skb, *ptr);
>> + } else {
>> + kfree_skb(bdev->rx_skb);
>> + bdev->rx_skb = NULL;
>> + bdev->rx_slip_state = SLIP_WAIT_DELIM;
>> + }
>> + }
>> + break;
>> + case SLIP_ESCAPE:
>> + /* As part of the escape sequence, only the octets
>> + * 0xDC for the delimiter and 0xDD for the escape
>> + * sequence are valid. All other octets are causing
>> + * re-sychronization with the delimter.
>> + */
>> + if (*ptr == SLIP_ESC_DELIM) {
>> + if (bdev->rx_skb->len < MAX_PACKET_SIZE) {
>> + skb_put_u8(bdev->rx_skb, SLIP_DELIM);
>> + } else {
>> + kfree_skb(bdev->rx_skb);
>> + bdev->rx_skb = NULL;
>> + bdev->rx_slip_state = SLIP_WAIT_DELIM;
>> + }
>> + bdev->rx_slip_state = SLIP_PACKET;
>
> Should this be in "if (bdev->rx_skb->len < MAX_PACKET_SIZE)" block?
> Otherwise a too-large packet is put in the SLIP_PACKET state instead of
> SLIP_WAIT_DELIM.
indeed, this is a bug. Good catch.
Regards
Marcel
next prev parent reply other threads:[~2018-03-18 19:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-16 22:12 [RFC] Bluetooth: Add new serdev based driver for 3-Wire attached controllers Marcel Holtmann
2018-03-18 18:23 ` Jeremy Cline
2018-03-18 19:35 ` Marcel Holtmann [this message]
2019-01-04 10:24 ` Emil Lenngren
2019-01-18 10:53 ` Marcel Holtmann
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=71DBC780-64EE-43C9-83E7-4B2F58249EF3@holtmann.org \
--to=marcel@holtmann.org \
--cc=jeremy@jcline.org \
--cc=linux-bluetooth@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).