diff options
-rw-r--r-- | drivers/nfc/pn533.c | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c index ed8ecb3589be..7040106cb7f2 100644 --- a/drivers/nfc/pn533.c +++ b/drivers/nfc/pn533.c | |||
@@ -82,10 +82,12 @@ MODULE_DEVICE_TABLE(usb, pn533_table); | |||
82 | #define PN533_NORMAL_FRAME_MAX_LEN 262 /* 6 (PREAMBLE, SOF, LEN, LCS, TFI) | 82 | #define PN533_NORMAL_FRAME_MAX_LEN 262 /* 6 (PREAMBLE, SOF, LEN, LCS, TFI) |
83 | 254 (DATA) | 83 | 254 (DATA) |
84 | 2 (DCS, postamble) */ | 84 | 2 (DCS, postamble) */ |
85 | #define PN533_FRAME_HEADER_LEN (sizeof(struct pn533_frame) \ | ||
86 | + 2) /* data[0] TFI, data[1] CC */ | ||
87 | #define PN533_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/ | ||
85 | 88 | ||
86 | #define PN533_FRAME_TAIL_SIZE 2 | ||
87 | #define PN533_FRAME_SIZE(f) (sizeof(struct pn533_frame) + f->datalen + \ | 89 | #define PN533_FRAME_SIZE(f) (sizeof(struct pn533_frame) + f->datalen + \ |
88 | PN533_FRAME_TAIL_SIZE) | 90 | PN533_FRAME_TAIL_LEN) |
89 | #define PN533_FRAME_ACK_SIZE (sizeof(struct pn533_frame) + 1) | 91 | #define PN533_FRAME_ACK_SIZE (sizeof(struct pn533_frame) + 1) |
90 | #define PN533_FRAME_CHECKSUM(f) (f->data[f->datalen]) | 92 | #define PN533_FRAME_CHECKSUM(f) (f->data[f->datalen]) |
91 | #define PN533_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1]) | 93 | #define PN533_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1]) |
@@ -1233,7 +1235,7 @@ static int pn533_init_target_frame(struct pn533_frame *frame, | |||
1233 | return 0; | 1235 | return 0; |
1234 | } | 1236 | } |
1235 | 1237 | ||
1236 | #define PN533_CMD_DATAEXCH_HEAD_LEN (sizeof(struct pn533_frame) + 3) | 1238 | #define PN533_CMD_DATAEXCH_HEAD_LEN 1 |
1237 | #define PN533_CMD_DATAEXCH_DATA_MAXLEN 262 | 1239 | #define PN533_CMD_DATAEXCH_DATA_MAXLEN 262 |
1238 | static int pn533_tm_get_data_complete(struct pn533 *dev, void *arg, | 1240 | static int pn533_tm_get_data_complete(struct pn533 *dev, void *arg, |
1239 | u8 *params, int params_len) | 1241 | u8 *params, int params_len) |
@@ -1261,8 +1263,9 @@ static int pn533_tm_get_data_complete(struct pn533 *dev, void *arg, | |||
1261 | } | 1263 | } |
1262 | 1264 | ||
1263 | skb_put(skb_resp, PN533_FRAME_SIZE(in_frame)); | 1265 | skb_put(skb_resp, PN533_FRAME_SIZE(in_frame)); |
1264 | skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN); | 1266 | skb_pull(skb_resp, |
1265 | skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_SIZE); | 1267 | PN533_FRAME_HEADER_LEN + PN533_CMD_DATAEXCH_HEAD_LEN); |
1268 | skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_LEN); | ||
1266 | 1269 | ||
1267 | return nfc_tm_data_received(dev->nfc_dev, skb_resp); | 1270 | return nfc_tm_data_received(dev->nfc_dev, skb_resp); |
1268 | } | 1271 | } |
@@ -1276,9 +1279,10 @@ static void pn533_wq_tg_get_data(struct work_struct *work) | |||
1276 | 1279 | ||
1277 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); | 1280 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); |
1278 | 1281 | ||
1279 | skb_resp_len = PN533_CMD_DATAEXCH_HEAD_LEN + | 1282 | skb_resp_len = PN533_FRAME_HEADER_LEN + |
1280 | PN533_CMD_DATAEXCH_DATA_MAXLEN + | 1283 | PN533_CMD_DATAEXCH_HEAD_LEN + |
1281 | PN533_FRAME_TAIL_SIZE; | 1284 | PN533_CMD_DATAEXCH_DATA_MAXLEN + |
1285 | PN533_FRAME_TAIL_LEN; | ||
1282 | 1286 | ||
1283 | skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL); | 1287 | skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL); |
1284 | if (!skb_resp) | 1288 | if (!skb_resp) |
@@ -1859,11 +1863,12 @@ static int pn533_build_tx_frame(struct pn533 *dev, struct sk_buff *skb, | |||
1859 | return -ENOSYS; | 1863 | return -ENOSYS; |
1860 | } | 1864 | } |
1861 | 1865 | ||
1866 | skb_push(skb, PN533_FRAME_HEADER_LEN); | ||
1867 | |||
1862 | if (target == true) { | 1868 | if (target == true) { |
1863 | switch (dev->device_type) { | 1869 | switch (dev->device_type) { |
1864 | case PN533_DEVICE_PASORI: | 1870 | case PN533_DEVICE_PASORI: |
1865 | if (dev->tgt_active_prot == NFC_PROTO_FELICA) { | 1871 | if (dev->tgt_active_prot == NFC_PROTO_FELICA) { |
1866 | skb_push(skb, PN533_CMD_DATAEXCH_HEAD_LEN - 1); | ||
1867 | out_frame = (struct pn533_frame *) skb->data; | 1872 | out_frame = (struct pn533_frame *) skb->data; |
1868 | pn533_tx_frame_init(out_frame, | 1873 | pn533_tx_frame_init(out_frame, |
1869 | PN533_CMD_IN_COMM_THRU); | 1874 | PN533_CMD_IN_COMM_THRU); |
@@ -1895,7 +1900,7 @@ static int pn533_build_tx_frame(struct pn533 *dev, struct sk_buff *skb, | |||
1895 | out_frame->datalen += payload_len; | 1900 | out_frame->datalen += payload_len; |
1896 | 1901 | ||
1897 | pn533_tx_frame_finish(out_frame); | 1902 | pn533_tx_frame_finish(out_frame); |
1898 | skb_put(skb, PN533_FRAME_TAIL_SIZE); | 1903 | skb_put(skb, PN533_FRAME_TAIL_LEN); |
1899 | 1904 | ||
1900 | return 0; | 1905 | return 0; |
1901 | } | 1906 | } |
@@ -1975,8 +1980,9 @@ static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg, | |||
1975 | } | 1980 | } |
1976 | 1981 | ||
1977 | skb_put(skb_resp, PN533_FRAME_SIZE(in_frame)); | 1982 | skb_put(skb_resp, PN533_FRAME_SIZE(in_frame)); |
1983 | skb_pull(skb_resp, PN533_FRAME_HEADER_LEN); | ||
1978 | skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN); | 1984 | skb_pull(skb_resp, PN533_CMD_DATAEXCH_HEAD_LEN); |
1979 | skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_SIZE); | 1985 | skb_trim(skb_resp, skb_resp->len - PN533_FRAME_TAIL_LEN); |
1980 | skb_queue_tail(&dev->resp_q, skb_resp); | 1986 | skb_queue_tail(&dev->resp_q, skb_resp); |
1981 | 1987 | ||
1982 | if (status & PN533_CMD_MI_MASK) { | 1988 | if (status & PN533_CMD_MI_MASK) { |
@@ -2024,9 +2030,10 @@ static int pn533_transceive(struct nfc_dev *nfc_dev, | |||
2024 | if (rc) | 2030 | if (rc) |
2025 | goto error; | 2031 | goto error; |
2026 | 2032 | ||
2027 | skb_resp_len = PN533_CMD_DATAEXCH_HEAD_LEN + | 2033 | skb_resp_len = PN533_FRAME_HEADER_LEN + |
2028 | PN533_CMD_DATAEXCH_DATA_MAXLEN + | 2034 | PN533_CMD_DATAEXCH_HEAD_LEN + |
2029 | PN533_FRAME_TAIL_SIZE; | 2035 | PN533_CMD_DATAEXCH_DATA_MAXLEN + |
2036 | PN533_FRAME_TAIL_LEN; | ||
2030 | 2037 | ||
2031 | skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL); | 2038 | skb_resp = nfc_alloc_recv_skb(skb_resp_len, GFP_KERNEL); |
2032 | if (!skb_resp) { | 2039 | if (!skb_resp) { |
@@ -2143,20 +2150,25 @@ static void pn533_wq_mi_recv(struct work_struct *work) | |||
2143 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); | 2150 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); |
2144 | 2151 | ||
2145 | /* This is a zero payload size skb */ | 2152 | /* This is a zero payload size skb */ |
2146 | skb_cmd = alloc_skb(PN533_CMD_DATAEXCH_HEAD_LEN + PN533_FRAME_TAIL_SIZE, | 2153 | skb_cmd = alloc_skb(PN533_FRAME_HEADER_LEN + |
2154 | PN533_CMD_DATAEXCH_HEAD_LEN + | ||
2155 | PN533_FRAME_TAIL_LEN, | ||
2147 | GFP_KERNEL); | 2156 | GFP_KERNEL); |
2148 | if (skb_cmd == NULL) | 2157 | if (skb_cmd == NULL) |
2149 | goto error_cmd; | 2158 | goto error_cmd; |
2150 | 2159 | ||
2151 | skb_reserve(skb_cmd, PN533_CMD_DATAEXCH_HEAD_LEN); | 2160 | skb_reserve(skb_cmd, |
2161 | PN533_FRAME_HEADER_LEN + PN533_CMD_DATAEXCH_HEAD_LEN); | ||
2152 | 2162 | ||
2153 | rc = pn533_build_tx_frame(dev, skb_cmd, true); | 2163 | rc = pn533_build_tx_frame(dev, skb_cmd, true); |
2154 | if (rc) | 2164 | if (rc) |
2155 | goto error_frame; | 2165 | goto error_frame; |
2156 | 2166 | ||
2157 | skb_resp_len = PN533_CMD_DATAEXCH_HEAD_LEN + | 2167 | skb_resp_len = PN533_FRAME_HEADER_LEN + |
2158 | PN533_CMD_DATAEXCH_DATA_MAXLEN + | 2168 | PN533_CMD_DATAEXCH_HEAD_LEN + |
2159 | PN533_FRAME_TAIL_SIZE; | 2169 | PN533_CMD_DATAEXCH_DATA_MAXLEN + |
2170 | PN533_FRAME_TAIL_LEN; | ||
2171 | |||
2160 | skb_resp = alloc_skb(skb_resp_len, GFP_KERNEL); | 2172 | skb_resp = alloc_skb(skb_resp_len, GFP_KERNEL); |
2161 | if (!skb_resp) { | 2173 | if (!skb_resp) { |
2162 | rc = -ENOMEM; | 2174 | rc = -ENOMEM; |
@@ -2433,8 +2445,9 @@ static int pn533_probe(struct usb_interface *interface, | |||
2433 | } | 2445 | } |
2434 | 2446 | ||
2435 | dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols, | 2447 | dev->nfc_dev = nfc_allocate_device(&pn533_nfc_ops, protocols, |
2448 | PN533_FRAME_HEADER_LEN + | ||
2436 | PN533_CMD_DATAEXCH_HEAD_LEN, | 2449 | PN533_CMD_DATAEXCH_HEAD_LEN, |
2437 | PN533_FRAME_TAIL_SIZE); | 2450 | PN533_FRAME_TAIL_LEN); |
2438 | if (!dev->nfc_dev) | 2451 | if (!dev->nfc_dev) |
2439 | goto destroy_wq; | 2452 | goto destroy_wq; |
2440 | 2453 | ||