Commit a80509c7 authored by Mark A. Greer's avatar Mark A. Greer Committed by Samuel Ortiz

NFC: digital: Add NFC-DEP Initiator-side NACK Support

When an NFC-DEP Initiator receives a frame with
an incorrect CRC or with a parity error, and the
frame is at least 4 bytes long, its supposed to
send a NACK to the Target.  The Initiator can
send up to 'N(retry,nack)' consecutive NACKs
where 2 <= 'N(retry,nack)' <= 5.  When the limit
is exceeded, a PROTOCOL EXCEPTION is raised.
Any other type of transmission error is to be
ignored and the Initiator should continue
waiting for a new frame.  This is described
in section 14.12.5.4 of the NFC Digital Protocol
Spec.

The digital layer's NFC-DEP code doesn't implement
any of this so add it.  This support diverges from
the spec in two significant ways:

a) NACKs will be sent for ANY error reported by the
   driver except a timeout.  This is done because
   there is currently no way for the digital layer
   to distinguish a CRC or parity error from any
   other type of error reported by the driver.

b) All other errors will cause a PROTOCOL EXCEPTION
   even frames with CRC errors that are less than 4
   bytes.

The value chosen for 'N(retry,nack)' is 2.

Targets do not send NACK PDUs.
Reviewed-by: default avatarThierry Escande <thierry.escande@linux.intel.com>
Tested-by: default avatarThierry Escande <thierry.escande@linux.intel.com>
Signed-off-by: default avatarMark A. Greer <mgreer@animalcreek.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent c12715ab
...@@ -233,6 +233,8 @@ struct nfc_digital_dev { ...@@ -233,6 +233,8 @@ struct nfc_digital_dev {
struct sk_buff *chaining_skb; struct sk_buff *chaining_skb;
struct digital_data_exch *data_exch; struct digital_data_exch *data_exch;
int nack_count;
u16 target_fsc; u16 target_fsc;
int (*skb_check_crc)(struct sk_buff *skb); int (*skb_check_crc)(struct sk_buff *skb);
......
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
#include "digital.h" #include "digital.h"
#define DIGITAL_NFC_DEP_N_RETRY_NACK 2
#define DIGITAL_NFC_DEP_FRAME_DIR_OUT 0xD4 #define DIGITAL_NFC_DEP_FRAME_DIR_OUT 0xD4
#define DIGITAL_NFC_DEP_FRAME_DIR_IN 0xD5 #define DIGITAL_NFC_DEP_FRAME_DIR_IN 0xD5
...@@ -529,6 +531,38 @@ static int digital_in_send_ack(struct nfc_digital_dev *ddev, ...@@ -529,6 +531,38 @@ static int digital_in_send_ack(struct nfc_digital_dev *ddev,
return rc; return rc;
} }
static int digital_in_send_nack(struct nfc_digital_dev *ddev,
struct digital_data_exch *data_exch)
{
struct digital_dep_req_res *dep_req;
struct sk_buff *skb;
int rc;
skb = digital_skb_alloc(ddev, 1);
if (!skb)
return -ENOMEM;
skb_push(skb, sizeof(struct digital_dep_req_res));
dep_req = (struct digital_dep_req_res *)skb->data;
dep_req->dir = DIGITAL_NFC_DEP_FRAME_DIR_OUT;
dep_req->cmd = DIGITAL_CMD_DEP_REQ;
dep_req->pfb = DIGITAL_NFC_DEP_PFB_ACK_NACK_PDU |
DIGITAL_NFC_DEP_PFB_NACK_BIT | ddev->curr_nfc_dep_pni;
digital_skb_push_dep_sod(ddev, skb);
ddev->skb_add_crc(skb);
rc = digital_in_send_cmd(ddev, skb, 1500, digital_in_recv_dep_res,
data_exch);
if (rc)
kfree_skb(skb);
return rc;
}
static int digital_in_send_rtox(struct nfc_digital_dev *ddev, static int digital_in_send_rtox(struct nfc_digital_dev *ddev,
struct digital_data_exch *data_exch, u8 rtox) struct digital_data_exch *data_exch, u8 rtox)
{ {
...@@ -575,20 +609,43 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg, ...@@ -575,20 +609,43 @@ static void digital_in_recv_dep_res(struct nfc_digital_dev *ddev, void *arg,
if (IS_ERR(resp)) { if (IS_ERR(resp)) {
rc = PTR_ERR(resp); rc = PTR_ERR(resp);
resp = NULL; resp = NULL;
if ((rc != -ETIMEDOUT) &&
(ddev->nack_count++ < DIGITAL_NFC_DEP_N_RETRY_NACK)) {
rc = digital_in_send_nack(ddev, data_exch);
if (rc)
goto error;
return;
}
goto exit;
}
rc = digital_skb_pull_dep_sod(ddev, resp);
if (rc) {
PROTOCOL_ERR("14.4.1.2");
goto exit; goto exit;
} }
rc = ddev->skb_check_crc(resp); rc = ddev->skb_check_crc(resp);
if (rc) { if (rc) {
if ((resp->len >= 4) &&
(ddev->nack_count++ < DIGITAL_NFC_DEP_N_RETRY_NACK)) {
rc = digital_in_send_nack(ddev, data_exch);
if (rc)
goto error;
kfree_skb(resp);
return;
}
PROTOCOL_ERR("14.4.1.6"); PROTOCOL_ERR("14.4.1.6");
goto error; goto error;
} }
rc = digital_skb_pull_dep_sod(ddev, resp); ddev->nack_count = 0;
if (rc) {
PROTOCOL_ERR("14.4.1.2");
goto exit;
}
if (resp->len > ddev->local_payload_max) { if (resp->len > ddev->local_payload_max) {
rc = -EMSGSIZE; rc = -EMSGSIZE;
...@@ -721,6 +778,8 @@ int digital_in_send_dep_req(struct nfc_digital_dev *ddev, ...@@ -721,6 +778,8 @@ int digital_in_send_dep_req(struct nfc_digital_dev *ddev,
dep_req->cmd = DIGITAL_CMD_DEP_REQ; dep_req->cmd = DIGITAL_CMD_DEP_REQ;
dep_req->pfb = ddev->curr_nfc_dep_pni; dep_req->pfb = ddev->curr_nfc_dep_pni;
ddev->nack_count = 0;
chaining_skb = ddev->chaining_skb; chaining_skb = ddev->chaining_skb;
tmp_skb = digital_send_dep_data_prep(ddev, skb, dep_req, data_exch); tmp_skb = digital_send_dep_data_prep(ddev, skb, dep_req, data_exch);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment