Devicetree
 help / color / mirror / Atom feed
From: Christophe Ricard <christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-nfc-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org,
	sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.org
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	christophe.ricard-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	christophe-h.ricard-qxv4g6HH51o@public.gmane.org
Subject: [PATCH 02/10] NFC: st21nfca: Fix incorrect TAILROOM and st21nfca_hci_remove_len_crc.
Date: Thu, 24 Apr 2014 23:19:31 +0200	[thread overview]
Message-ID: <1398374379-17133-3-git-send-email-christophe-h.ricard@st.com> (raw)
In-Reply-To: <1398374379-17133-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>

There is no byte stuffing when data are storred in skb.
TAILROOM is 2 byte crc + 1 byte eof.

st21nfca_hci_remove_len_crc was doing an incorrect operation on
the TAILROOM data.
If shdlc timer T2 is triggered, it will request to send the same data.
Before every hci data was lost after st21nfca_hci_remove_len_crc.

Signed-off-by: Christophe Ricard <christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
---
 drivers/nfc/st21nfca/i2c.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/drivers/nfc/st21nfca/i2c.c b/drivers/nfc/st21nfca/i2c.c
index 6c4d0a0..5535d02 100644
--- a/drivers/nfc/st21nfca/i2c.c
+++ b/drivers/nfc/st21nfca/i2c.c
@@ -48,11 +48,11 @@
 #define ST21NFCA_BYTE_STUFFING_MASK	0x20
 #define ST21NFCA_ESCAPE_BYTE_STUFFING	0x7d
 
-/* SOF + 00 fill size */
+/* SOF + 00 */
 #define ST21NFCA_FRAME_HEADROOM			2
 
-/* 4 bytes crc (worst case byte stuffing) + EOF */
-#define ST21NFCA_FRAME_TAILROOM 5
+/* 2 bytes crc + EOF */
+#define ST21NFCA_FRAME_TAILROOM 3
 
 #define ST21NFCA_HCI_I2C_DRIVER_NAME "st21nfca_hci_i2c"
 
@@ -166,9 +166,8 @@ static void st21nfca_hci_i2c_disable(void *phy_id)
 	phy->powered = 0;
 }
 
-static int st21nfca_hci_add_len_crc(struct sk_buff *skb)
+static void st21nfca_hci_add_len_crc(struct sk_buff *skb)
 {
-	int ret = 2;
 	u16 crc;
 	u8 tmp;
 
@@ -182,14 +181,12 @@ static int st21nfca_hci_add_len_crc(struct sk_buff *skb)
 
 	tmp = (crc >> 8) & 0x00ff;
 	*skb_put(skb, 1) = tmp;
-
-	return ret;
 }
 
-static void st21nfca_hci_remove_len_crc(struct sk_buff *skb, int crc_len)
+static void st21nfca_hci_remove_len_crc(struct sk_buff *skb)
 {
 	skb_pull(skb, ST21NFCA_FRAME_HEADROOM);
-	skb_trim(skb, crc_len);
+	skb_trim(skb, skb->len - ST21NFCA_FRAME_TAILROOM);
 }
 
 /*
@@ -199,7 +196,7 @@ static void st21nfca_hci_remove_len_crc(struct sk_buff *skb, int crc_len)
  */
 static int st21nfca_hci_i2c_write(void *phy_id, struct sk_buff *skb)
 {
-	int r = -1, i, j, len;
+	int r = -1, i, j;
 	struct st21nfca_i2c_phy *phy = phy_id;
 	struct i2c_client *client = phy->i2c_dev;
 	u8 tmp[ST21NFCA_HCI_LLC_MAX_SIZE * 2];
@@ -215,7 +212,7 @@ static int st21nfca_hci_i2c_write(void *phy_id, struct sk_buff *skb)
 	 * Note st21nfca_hci_add_len_crc is doing a byte stuffing
 	 * on its own value
 	 */
-	len = st21nfca_hci_add_len_crc(skb);
+	st21nfca_hci_add_len_crc(skb);
 
 	/* add ST21NFCA_SOF_EOF on tail */
 	*skb_put(skb, 1) = ST21NFCA_SOF_EOF;
@@ -259,7 +256,7 @@ static int st21nfca_hci_i2c_write(void *phy_id, struct sk_buff *skb)
 			r = 0;
 	}
 
-	st21nfca_hci_remove_len_crc(skb, len);
+	st21nfca_hci_remove_len_crc(skb);
 
 	return r;
 }
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2014-04-24 21:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-24 21:19 [PATCH 00/10] Clean up, DTS and ISO15693 support Christophe Ricard
     [not found] ` <1398374379-17133-1-git-send-email-christophe-h.ricard-qxv4g6HH51o@public.gmane.org>
2014-04-24 21:19   ` [PATCH 01/10] NFC: st21nfca: Remove few useless include Christophe Ricard
2014-04-24 21:19   ` Christophe Ricard [this message]
2014-04-24 21:19   ` [PATCH 03/10] NFC: st21nfca: Fix incorrect byte stuffing revocation Christophe Ricard
2014-04-24 21:19   ` [PATCH 04/10] NFC: st21nfca: Improved check for correct data reception on i2c bus Christophe Ricard
2014-04-24 21:19   ` [PATCH 05/10] NFC: st21nfca: Add mutex to force a successful i2c transaction Christophe Ricard
2014-04-24 21:19   ` [PATCH 06/10] NFC: st21nfca: Free buffer when a bad frame is detected Christophe Ricard
2014-04-24 21:19   ` [PATCH 07/10] NFC: dts: st21nfca: Add device-tree (Open Firmware) support to st21nfca Christophe Ricard
2014-04-24 21:19   ` [PATCH 08/10] NFC: dts: st21nfca_i2c: Add DTS Documentation Christophe Ricard
2014-04-24 21:19   ` [PATCH 09/10] NFC: st21nfca: Improve load_session in order to create pipe when it does not exists Christophe Ricard
2014-04-24 21:19   ` [PATCH 10/10] NFC: st21nfca: Add ISO15693 Reader/Writer support Christophe Ricard
2014-05-04 23:09   ` [PATCH 00/10] Clean up, DTS and ISO15693 support Samuel Ortiz

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=1398374379-17133-3-git-send-email-christophe-h.ricard@st.com \
    --to=christophe.ricard-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=christophe-h.ricard-qxv4g6HH51o@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-nfc-hn68Rpc1hR1g9hUCZPvPmw@public.gmane.org \
    --cc=sameo-VuQAYsv1563Yd54FQh9/CA@public.gmane.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