st21nfca_dep.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*
  2. * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include <net/nfc/hci.h>
  17. #include "st21nfca.h"
  18. #include "st21nfca_dep.h"
  19. #define ST21NFCA_NFCIP1_INITIATOR 0x00
  20. #define ST21NFCA_NFCIP1_REQ 0xd4
  21. #define ST21NFCA_NFCIP1_RES 0xd5
  22. #define ST21NFCA_NFCIP1_ATR_REQ 0x00
  23. #define ST21NFCA_NFCIP1_ATR_RES 0x01
  24. #define ST21NFCA_NFCIP1_PSL_REQ 0x04
  25. #define ST21NFCA_NFCIP1_PSL_RES 0x05
  26. #define ST21NFCA_NFCIP1_DEP_REQ 0x06
  27. #define ST21NFCA_NFCIP1_DEP_RES 0x07
  28. #define ST21NFCA_NFC_DEP_PFB_PNI(pfb) ((pfb) & 0x03)
  29. #define ST21NFCA_NFC_DEP_PFB_TYPE(pfb) ((pfb) & 0xE0)
  30. #define ST21NFCA_NFC_DEP_PFB_IS_TIMEOUT(pfb) \
  31. ((pfb) & ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT)
  32. #define ST21NFCA_NFC_DEP_DID_BIT_SET(pfb) ((pfb) & 0x04)
  33. #define ST21NFCA_NFC_DEP_NAD_BIT_SET(pfb) ((pfb) & 0x08)
  34. #define ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT 0x10
  35. #define ST21NFCA_NFC_DEP_PFB_IS_TIMEOUT(pfb) \
  36. ((pfb) & ST21NFCA_NFC_DEP_PFB_TIMEOUT_BIT)
  37. #define ST21NFCA_NFC_DEP_PFB_I_PDU 0x00
  38. #define ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU 0x40
  39. #define ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU 0x80
  40. #define ST21NFCA_ATR_REQ_MIN_SIZE 17
  41. #define ST21NFCA_ATR_REQ_MAX_SIZE 65
  42. #define ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B 0x30
  43. #define ST21NFCA_GB_BIT 0x02
  44. #define ST21NFCA_EVT_CARD_F_BITRATE 0x16
  45. #define ST21NFCA_EVT_READER_F_BITRATE 0x13
  46. #define ST21NFCA_PSL_REQ_SEND_SPEED(brs) (brs & 0x38)
  47. #define ST21NFCA_PSL_REQ_RECV_SPEED(brs) (brs & 0x07)
  48. #define ST21NFCA_PP2LRI(pp) ((pp & 0x30) >> 4)
  49. #define ST21NFCA_CARD_BITRATE_212 0x01
  50. #define ST21NFCA_CARD_BITRATE_424 0x02
  51. #define ST21NFCA_DEFAULT_TIMEOUT 0x0a
  52. #define PROTOCOL_ERR(req) pr_err("%d: ST21NFCA Protocol error: %s\n", \
  53. __LINE__, req)
  54. struct st21nfca_atr_req {
  55. u8 length;
  56. u8 cmd0;
  57. u8 cmd1;
  58. u8 nfcid3[NFC_NFCID3_MAXSIZE];
  59. u8 did;
  60. u8 bsi;
  61. u8 bri;
  62. u8 ppi;
  63. u8 gbi[0];
  64. } __packed;
  65. struct st21nfca_atr_res {
  66. u8 length;
  67. u8 cmd0;
  68. u8 cmd1;
  69. u8 nfcid3[NFC_NFCID3_MAXSIZE];
  70. u8 did;
  71. u8 bsi;
  72. u8 bri;
  73. u8 to;
  74. u8 ppi;
  75. u8 gbi[0];
  76. } __packed;
  77. struct st21nfca_psl_req {
  78. u8 length;
  79. u8 cmd0;
  80. u8 cmd1;
  81. u8 did;
  82. u8 brs;
  83. u8 fsl;
  84. } __packed;
  85. struct st21nfca_psl_res {
  86. u8 length;
  87. u8 cmd0;
  88. u8 cmd1;
  89. u8 did;
  90. } __packed;
  91. struct st21nfca_dep_req_res {
  92. u8 length;
  93. u8 cmd0;
  94. u8 cmd1;
  95. u8 pfb;
  96. u8 did;
  97. u8 nad;
  98. } __packed;
  99. static void st21nfca_tx_work(struct work_struct *work)
  100. {
  101. struct st21nfca_hci_info *info = container_of(work,
  102. struct st21nfca_hci_info,
  103. dep_info.tx_work);
  104. struct nfc_dev *dev;
  105. struct sk_buff *skb;
  106. if (info) {
  107. dev = info->hdev->ndev;
  108. skb = info->dep_info.tx_pending;
  109. device_lock(&dev->dev);
  110. nfc_hci_send_cmd_async(info->hdev, ST21NFCA_RF_READER_F_GATE,
  111. ST21NFCA_WR_XCHG_DATA, skb->data, skb->len,
  112. info->async_cb, info);
  113. device_unlock(&dev->dev);
  114. kfree_skb(skb);
  115. }
  116. }
  117. static void st21nfca_im_send_pdu(struct st21nfca_hci_info *info,
  118. struct sk_buff *skb)
  119. {
  120. info->dep_info.tx_pending = skb;
  121. schedule_work(&info->dep_info.tx_work);
  122. }
  123. static int st21nfca_tm_send_atr_res(struct nfc_hci_dev *hdev,
  124. struct st21nfca_atr_req *atr_req)
  125. {
  126. struct st21nfca_atr_res *atr_res;
  127. struct sk_buff *skb;
  128. size_t gb_len;
  129. int r;
  130. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  131. gb_len = atr_req->length - sizeof(struct st21nfca_atr_req);
  132. skb = alloc_skb(atr_req->length + 1, GFP_KERNEL);
  133. if (!skb)
  134. return -ENOMEM;
  135. skb_put(skb, sizeof(struct st21nfca_atr_res));
  136. atr_res = (struct st21nfca_atr_res *)skb->data;
  137. memset(atr_res, 0, sizeof(struct st21nfca_atr_res));
  138. atr_res->length = atr_req->length + 1;
  139. atr_res->cmd0 = ST21NFCA_NFCIP1_RES;
  140. atr_res->cmd1 = ST21NFCA_NFCIP1_ATR_RES;
  141. memcpy(atr_res->nfcid3, atr_req->nfcid3, 6);
  142. atr_res->bsi = 0x00;
  143. atr_res->bri = 0x00;
  144. atr_res->to = ST21NFCA_DEFAULT_TIMEOUT;
  145. atr_res->ppi = ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B;
  146. if (gb_len) {
  147. skb_put(skb, gb_len);
  148. atr_res->ppi |= ST21NFCA_GB_BIT;
  149. memcpy(atr_res->gbi, atr_req->gbi, gb_len);
  150. r = nfc_set_remote_general_bytes(hdev->ndev, atr_res->gbi,
  151. gb_len);
  152. if (r < 0)
  153. return r;
  154. }
  155. info->dep_info.curr_nfc_dep_pni = 0;
  156. r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
  157. ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
  158. kfree_skb(skb);
  159. return r;
  160. }
  161. static int st21nfca_tm_recv_atr_req(struct nfc_hci_dev *hdev,
  162. struct sk_buff *skb)
  163. {
  164. struct st21nfca_atr_req *atr_req;
  165. size_t gb_len;
  166. int r;
  167. skb_trim(skb, skb->len - 1);
  168. if (!skb->len) {
  169. r = -EIO;
  170. goto exit;
  171. }
  172. if (skb->len < ST21NFCA_ATR_REQ_MIN_SIZE) {
  173. r = -EPROTO;
  174. goto exit;
  175. }
  176. atr_req = (struct st21nfca_atr_req *)skb->data;
  177. if (atr_req->length < sizeof(struct st21nfca_atr_req)) {
  178. r = -EPROTO;
  179. goto exit;
  180. }
  181. r = st21nfca_tm_send_atr_res(hdev, atr_req);
  182. if (r)
  183. goto exit;
  184. gb_len = skb->len - sizeof(struct st21nfca_atr_req);
  185. r = nfc_tm_activated(hdev->ndev, NFC_PROTO_NFC_DEP_MASK,
  186. NFC_COMM_PASSIVE, atr_req->gbi, gb_len);
  187. if (r)
  188. goto exit;
  189. r = 0;
  190. exit:
  191. return r;
  192. }
  193. static int st21nfca_tm_send_psl_res(struct nfc_hci_dev *hdev,
  194. struct st21nfca_psl_req *psl_req)
  195. {
  196. struct st21nfca_psl_res *psl_res;
  197. struct sk_buff *skb;
  198. u8 bitrate[2] = {0, 0};
  199. int r;
  200. skb = alloc_skb(sizeof(struct st21nfca_psl_res), GFP_KERNEL);
  201. if (!skb)
  202. return -ENOMEM;
  203. skb_put(skb, sizeof(struct st21nfca_psl_res));
  204. psl_res = (struct st21nfca_psl_res *)skb->data;
  205. psl_res->length = sizeof(struct st21nfca_psl_res);
  206. psl_res->cmd0 = ST21NFCA_NFCIP1_RES;
  207. psl_res->cmd1 = ST21NFCA_NFCIP1_PSL_RES;
  208. psl_res->did = psl_req->did;
  209. r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
  210. ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
  211. if (r < 0)
  212. goto error;
  213. /*
  214. * ST21NFCA only support P2P passive.
  215. * PSL_REQ BRS value != 0 has only a meaning to
  216. * change technology to type F.
  217. * We change to BITRATE 424Kbits.
  218. * In other case switch to BITRATE 106Kbits.
  219. */
  220. if (ST21NFCA_PSL_REQ_SEND_SPEED(psl_req->brs) &&
  221. ST21NFCA_PSL_REQ_RECV_SPEED(psl_req->brs)) {
  222. bitrate[0] = ST21NFCA_CARD_BITRATE_424;
  223. bitrate[1] = ST21NFCA_CARD_BITRATE_424;
  224. }
  225. /* Send an event to change bitrate change event to card f */
  226. r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
  227. ST21NFCA_EVT_CARD_F_BITRATE, bitrate, 2);
  228. error:
  229. kfree_skb(skb);
  230. return r;
  231. }
  232. static int st21nfca_tm_recv_psl_req(struct nfc_hci_dev *hdev,
  233. struct sk_buff *skb)
  234. {
  235. struct st21nfca_psl_req *psl_req;
  236. int r;
  237. skb_trim(skb, skb->len - 1);
  238. if (!skb->len) {
  239. r = -EIO;
  240. goto exit;
  241. }
  242. psl_req = (struct st21nfca_psl_req *)skb->data;
  243. if (skb->len < sizeof(struct st21nfca_psl_req)) {
  244. r = -EIO;
  245. goto exit;
  246. }
  247. r = st21nfca_tm_send_psl_res(hdev, psl_req);
  248. exit:
  249. return r;
  250. }
  251. int st21nfca_tm_send_dep_res(struct nfc_hci_dev *hdev, struct sk_buff *skb)
  252. {
  253. int r;
  254. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  255. *skb_push(skb, 1) = info->dep_info.curr_nfc_dep_pni;
  256. *skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_RES;
  257. *skb_push(skb, 1) = ST21NFCA_NFCIP1_RES;
  258. *skb_push(skb, 1) = skb->len;
  259. r = nfc_hci_send_event(hdev, ST21NFCA_RF_CARD_F_GATE,
  260. ST21NFCA_EVT_SEND_DATA, skb->data, skb->len);
  261. kfree_skb(skb);
  262. return r;
  263. }
  264. EXPORT_SYMBOL(st21nfca_tm_send_dep_res);
  265. static int st21nfca_tm_recv_dep_req(struct nfc_hci_dev *hdev,
  266. struct sk_buff *skb)
  267. {
  268. struct st21nfca_dep_req_res *dep_req;
  269. u8 size;
  270. int r;
  271. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  272. skb_trim(skb, skb->len - 1);
  273. size = 4;
  274. dep_req = (struct st21nfca_dep_req_res *)skb->data;
  275. if (skb->len < size) {
  276. r = -EIO;
  277. goto exit;
  278. }
  279. if (ST21NFCA_NFC_DEP_DID_BIT_SET(dep_req->pfb))
  280. size++;
  281. if (ST21NFCA_NFC_DEP_NAD_BIT_SET(dep_req->pfb))
  282. size++;
  283. if (skb->len < size) {
  284. r = -EIO;
  285. goto exit;
  286. }
  287. /* Receiving DEP_REQ - Decoding */
  288. switch (ST21NFCA_NFC_DEP_PFB_TYPE(dep_req->pfb)) {
  289. case ST21NFCA_NFC_DEP_PFB_I_PDU:
  290. info->dep_info.curr_nfc_dep_pni =
  291. ST21NFCA_NFC_DEP_PFB_PNI(dep_req->pfb);
  292. break;
  293. case ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU:
  294. pr_err("Received a ACK/NACK PDU\n");
  295. break;
  296. case ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU:
  297. pr_err("Received a SUPERVISOR PDU\n");
  298. break;
  299. }
  300. skb_pull(skb, size);
  301. return nfc_tm_data_received(hdev->ndev, skb);
  302. exit:
  303. return r;
  304. }
  305. int st21nfca_tm_event_send_data(struct nfc_hci_dev *hdev, struct sk_buff *skb,
  306. u8 gate)
  307. {
  308. u8 cmd0, cmd1;
  309. int r;
  310. cmd0 = skb->data[1];
  311. switch (cmd0) {
  312. case ST21NFCA_NFCIP1_REQ:
  313. cmd1 = skb->data[2];
  314. switch (cmd1) {
  315. case ST21NFCA_NFCIP1_ATR_REQ:
  316. r = st21nfca_tm_recv_atr_req(hdev, skb);
  317. break;
  318. case ST21NFCA_NFCIP1_PSL_REQ:
  319. r = st21nfca_tm_recv_psl_req(hdev, skb);
  320. break;
  321. case ST21NFCA_NFCIP1_DEP_REQ:
  322. r = st21nfca_tm_recv_dep_req(hdev, skb);
  323. break;
  324. default:
  325. return 1;
  326. }
  327. default:
  328. return 1;
  329. }
  330. return r;
  331. }
  332. EXPORT_SYMBOL(st21nfca_tm_event_send_data);
  333. static void st21nfca_im_send_psl_req(struct nfc_hci_dev *hdev, u8 did, u8 bsi,
  334. u8 bri, u8 lri)
  335. {
  336. struct sk_buff *skb;
  337. struct st21nfca_psl_req *psl_req;
  338. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  339. skb =
  340. alloc_skb(sizeof(struct st21nfca_psl_req) + 1, GFP_KERNEL);
  341. if (!skb)
  342. return;
  343. skb_reserve(skb, 1);
  344. skb_put(skb, sizeof(struct st21nfca_psl_req));
  345. psl_req = (struct st21nfca_psl_req *) skb->data;
  346. psl_req->length = sizeof(struct st21nfca_psl_req);
  347. psl_req->cmd0 = ST21NFCA_NFCIP1_REQ;
  348. psl_req->cmd1 = ST21NFCA_NFCIP1_PSL_REQ;
  349. psl_req->did = did;
  350. psl_req->brs = (0x30 & bsi << 4) | (bri & 0x03);
  351. psl_req->fsl = lri;
  352. *skb_push(skb, 1) = info->dep_info.to | 0x10;
  353. st21nfca_im_send_pdu(info, skb);
  354. }
  355. #define ST21NFCA_CB_TYPE_READER_F 1
  356. static void st21nfca_im_recv_atr_res_cb(void *context, struct sk_buff *skb,
  357. int err)
  358. {
  359. struct st21nfca_hci_info *info = context;
  360. struct st21nfca_atr_res *atr_res;
  361. int r;
  362. if (err != 0)
  363. return;
  364. if (!skb)
  365. return;
  366. switch (info->async_cb_type) {
  367. case ST21NFCA_CB_TYPE_READER_F:
  368. skb_trim(skb, skb->len - 1);
  369. atr_res = (struct st21nfca_atr_res *)skb->data;
  370. r = nfc_set_remote_general_bytes(info->hdev->ndev,
  371. atr_res->gbi,
  372. skb->len - sizeof(struct st21nfca_atr_res));
  373. if (r < 0)
  374. return;
  375. if (atr_res->to >= 0x0e)
  376. info->dep_info.to = 0x0e;
  377. else
  378. info->dep_info.to = atr_res->to + 1;
  379. info->dep_info.to |= 0x10;
  380. r = nfc_dep_link_is_up(info->hdev->ndev, info->dep_info.idx,
  381. NFC_COMM_PASSIVE, NFC_RF_INITIATOR);
  382. if (r < 0)
  383. return;
  384. info->dep_info.curr_nfc_dep_pni = 0;
  385. if (ST21NFCA_PP2LRI(atr_res->ppi) != info->dep_info.lri)
  386. st21nfca_im_send_psl_req(info->hdev, atr_res->did,
  387. atr_res->bsi, atr_res->bri,
  388. ST21NFCA_PP2LRI(atr_res->ppi));
  389. break;
  390. default:
  391. kfree_skb(skb);
  392. break;
  393. }
  394. }
  395. int st21nfca_im_send_atr_req(struct nfc_hci_dev *hdev, u8 *gb, size_t gb_len)
  396. {
  397. struct sk_buff *skb;
  398. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  399. struct st21nfca_atr_req *atr_req;
  400. struct nfc_target *target;
  401. uint size;
  402. info->dep_info.to = ST21NFCA_DEFAULT_TIMEOUT;
  403. size = ST21NFCA_ATR_REQ_MIN_SIZE + gb_len;
  404. if (size > ST21NFCA_ATR_REQ_MAX_SIZE) {
  405. PROTOCOL_ERR("14.6.1.1");
  406. return -EINVAL;
  407. }
  408. skb =
  409. alloc_skb(sizeof(struct st21nfca_atr_req) + gb_len + 1, GFP_KERNEL);
  410. if (!skb)
  411. return -ENOMEM;
  412. skb_reserve(skb, 1);
  413. skb_put(skb, sizeof(struct st21nfca_atr_req));
  414. atr_req = (struct st21nfca_atr_req *)skb->data;
  415. memset(atr_req, 0, sizeof(struct st21nfca_atr_req));
  416. atr_req->cmd0 = ST21NFCA_NFCIP1_REQ;
  417. atr_req->cmd1 = ST21NFCA_NFCIP1_ATR_REQ;
  418. memset(atr_req->nfcid3, 0, NFC_NFCID3_MAXSIZE);
  419. target = hdev->ndev->targets;
  420. if (target->sensf_res_len > 0)
  421. memcpy(atr_req->nfcid3, target->sensf_res,
  422. target->sensf_res_len);
  423. else
  424. get_random_bytes(atr_req->nfcid3, NFC_NFCID3_MAXSIZE);
  425. atr_req->did = 0x0;
  426. atr_req->bsi = 0x00;
  427. atr_req->bri = 0x00;
  428. atr_req->ppi = ST21NFCA_LR_BITS_PAYLOAD_SIZE_254B;
  429. if (gb_len) {
  430. atr_req->ppi |= ST21NFCA_GB_BIT;
  431. memcpy(skb_put(skb, gb_len), gb, gb_len);
  432. }
  433. atr_req->length = sizeof(struct st21nfca_atr_req) + hdev->gb_len;
  434. *skb_push(skb, 1) = info->dep_info.to | 0x10; /* timeout */
  435. info->async_cb_type = ST21NFCA_CB_TYPE_READER_F;
  436. info->async_cb_context = info;
  437. info->async_cb = st21nfca_im_recv_atr_res_cb;
  438. info->dep_info.bri = atr_req->bri;
  439. info->dep_info.bsi = atr_req->bsi;
  440. info->dep_info.lri = ST21NFCA_PP2LRI(atr_req->ppi);
  441. return nfc_hci_send_cmd_async(hdev, ST21NFCA_RF_READER_F_GATE,
  442. ST21NFCA_WR_XCHG_DATA, skb->data,
  443. skb->len, info->async_cb, info);
  444. }
  445. EXPORT_SYMBOL(st21nfca_im_send_atr_req);
  446. static void st21nfca_im_recv_dep_res_cb(void *context, struct sk_buff *skb,
  447. int err)
  448. {
  449. struct st21nfca_hci_info *info = context;
  450. struct st21nfca_dep_req_res *dep_res;
  451. int size;
  452. if (err != 0)
  453. return;
  454. if (!skb)
  455. return;
  456. switch (info->async_cb_type) {
  457. case ST21NFCA_CB_TYPE_READER_F:
  458. dep_res = (struct st21nfca_dep_req_res *)skb->data;
  459. size = 3;
  460. if (skb->len < size)
  461. goto exit;
  462. if (ST21NFCA_NFC_DEP_DID_BIT_SET(dep_res->pfb))
  463. size++;
  464. if (ST21NFCA_NFC_DEP_NAD_BIT_SET(dep_res->pfb))
  465. size++;
  466. if (skb->len < size)
  467. goto exit;
  468. skb_trim(skb, skb->len - 1);
  469. /* Receiving DEP_REQ - Decoding */
  470. switch (ST21NFCA_NFC_DEP_PFB_TYPE(dep_res->pfb)) {
  471. case ST21NFCA_NFC_DEP_PFB_ACK_NACK_PDU:
  472. pr_err("Received a ACK/NACK PDU\n");
  473. case ST21NFCA_NFC_DEP_PFB_I_PDU:
  474. info->dep_info.curr_nfc_dep_pni =
  475. ST21NFCA_NFC_DEP_PFB_PNI(dep_res->pfb + 1);
  476. size++;
  477. skb_pull(skb, size);
  478. nfc_tm_data_received(info->hdev->ndev, skb);
  479. break;
  480. case ST21NFCA_NFC_DEP_PFB_SUPERVISOR_PDU:
  481. pr_err("Received a SUPERVISOR PDU\n");
  482. skb_pull(skb, size);
  483. *skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_REQ;
  484. *skb_push(skb, 1) = ST21NFCA_NFCIP1_REQ;
  485. *skb_push(skb, 1) = skb->len;
  486. *skb_push(skb, 1) = info->dep_info.to | 0x10;
  487. st21nfca_im_send_pdu(info, skb);
  488. break;
  489. }
  490. return;
  491. default:
  492. break;
  493. }
  494. exit:
  495. kfree_skb(skb);
  496. }
  497. int st21nfca_im_send_dep_req(struct nfc_hci_dev *hdev, struct sk_buff *skb)
  498. {
  499. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  500. info->async_cb_type = ST21NFCA_CB_TYPE_READER_F;
  501. info->async_cb_context = info;
  502. info->async_cb = st21nfca_im_recv_dep_res_cb;
  503. *skb_push(skb, 1) = info->dep_info.curr_nfc_dep_pni;
  504. *skb_push(skb, 1) = ST21NFCA_NFCIP1_DEP_REQ;
  505. *skb_push(skb, 1) = ST21NFCA_NFCIP1_REQ;
  506. *skb_push(skb, 1) = skb->len;
  507. *skb_push(skb, 1) = info->dep_info.to | 0x10;
  508. return nfc_hci_send_cmd_async(hdev, ST21NFCA_RF_READER_F_GATE,
  509. ST21NFCA_WR_XCHG_DATA,
  510. skb->data, skb->len,
  511. info->async_cb, info);
  512. }
  513. EXPORT_SYMBOL(st21nfca_im_send_dep_req);
  514. void st21nfca_dep_init(struct nfc_hci_dev *hdev)
  515. {
  516. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  517. INIT_WORK(&info->dep_info.tx_work, st21nfca_tx_work);
  518. info->dep_info.curr_nfc_dep_pni = 0;
  519. info->dep_info.idx = 0;
  520. info->dep_info.to = ST21NFCA_DEFAULT_TIMEOUT;
  521. }
  522. EXPORT_SYMBOL(st21nfca_dep_init);
  523. void st21nfca_dep_deinit(struct nfc_hci_dev *hdev)
  524. {
  525. struct st21nfca_hci_info *info = nfc_hci_get_clientdata(hdev);
  526. cancel_work_sync(&info->dep_info.tx_work);
  527. }
  528. EXPORT_SYMBOL(st21nfca_dep_deinit);