ntf.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  1. /*
  2. * The NFC Controller Interface is the communication protocol between an
  3. * NFC Controller (NFCC) and a Device Host (DH).
  4. *
  5. * Copyright (C) 2011 Texas Instruments, Inc.
  6. *
  7. * Written by Ilan Elias <ilane@ti.com>
  8. *
  9. * Acknowledgements:
  10. * This file is based on hci_event.c, which was written
  11. * by Maxim Krasnyansky.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License version 2
  15. * as published by the Free Software Foundation
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
  28. #include <linux/types.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/bitops.h>
  31. #include <linux/skbuff.h>
  32. #include "../nfc.h"
  33. #include <net/nfc/nci.h>
  34. #include <net/nfc/nci_core.h>
  35. #include <linux/nfc.h>
  36. /* Handle NCI Notification packets */
  37. static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
  38. struct sk_buff *skb)
  39. {
  40. struct nci_core_conn_credit_ntf *ntf = (void *) skb->data;
  41. int i;
  42. pr_debug("num_entries %d\n", ntf->num_entries);
  43. if (ntf->num_entries > NCI_MAX_NUM_CONN)
  44. ntf->num_entries = NCI_MAX_NUM_CONN;
  45. /* update the credits */
  46. for (i = 0; i < ntf->num_entries; i++) {
  47. ntf->conn_entries[i].conn_id =
  48. nci_conn_id(&ntf->conn_entries[i].conn_id);
  49. pr_debug("entry[%d]: conn_id %d, credits %d\n",
  50. i, ntf->conn_entries[i].conn_id,
  51. ntf->conn_entries[i].credits);
  52. if (ntf->conn_entries[i].conn_id == NCI_STATIC_RF_CONN_ID) {
  53. /* found static rf connection */
  54. atomic_add(ntf->conn_entries[i].credits,
  55. &ndev->credits_cnt);
  56. }
  57. }
  58. /* trigger the next tx */
  59. if (!skb_queue_empty(&ndev->tx_q))
  60. queue_work(ndev->tx_wq, &ndev->tx_work);
  61. }
  62. static void nci_core_generic_error_ntf_packet(struct nci_dev *ndev,
  63. struct sk_buff *skb)
  64. {
  65. __u8 status = skb->data[0];
  66. pr_debug("status 0x%x\n", status);
  67. if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) {
  68. /* Activation failed, so complete the request
  69. (the state remains the same) */
  70. nci_req_complete(ndev, status);
  71. }
  72. }
  73. static void nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev,
  74. struct sk_buff *skb)
  75. {
  76. struct nci_core_intf_error_ntf *ntf = (void *) skb->data;
  77. ntf->conn_id = nci_conn_id(&ntf->conn_id);
  78. pr_debug("status 0x%x, conn_id %d\n", ntf->status, ntf->conn_id);
  79. /* complete the data exchange transaction, if exists */
  80. if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
  81. nci_data_exchange_complete(ndev, NULL, -EIO);
  82. }
  83. static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev,
  84. struct rf_tech_specific_params_nfca_poll *nfca_poll,
  85. __u8 *data)
  86. {
  87. nfca_poll->sens_res = __le16_to_cpu(*((__u16 *)data));
  88. data += 2;
  89. nfca_poll->nfcid1_len = min_t(__u8, *data++, NFC_NFCID1_MAXSIZE);
  90. pr_debug("sens_res 0x%x, nfcid1_len %d\n",
  91. nfca_poll->sens_res, nfca_poll->nfcid1_len);
  92. memcpy(nfca_poll->nfcid1, data, nfca_poll->nfcid1_len);
  93. data += nfca_poll->nfcid1_len;
  94. nfca_poll->sel_res_len = *data++;
  95. if (nfca_poll->sel_res_len != 0)
  96. nfca_poll->sel_res = *data++;
  97. pr_debug("sel_res_len %d, sel_res 0x%x\n",
  98. nfca_poll->sel_res_len,
  99. nfca_poll->sel_res);
  100. return data;
  101. }
  102. static __u8 *nci_extract_rf_params_nfcb_passive_poll(struct nci_dev *ndev,
  103. struct rf_tech_specific_params_nfcb_poll *nfcb_poll,
  104. __u8 *data)
  105. {
  106. nfcb_poll->sensb_res_len = min_t(__u8, *data++, NFC_SENSB_RES_MAXSIZE);
  107. pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len);
  108. memcpy(nfcb_poll->sensb_res, data, nfcb_poll->sensb_res_len);
  109. data += nfcb_poll->sensb_res_len;
  110. return data;
  111. }
  112. static __u8 *nci_extract_rf_params_nfcf_passive_poll(struct nci_dev *ndev,
  113. struct rf_tech_specific_params_nfcf_poll *nfcf_poll,
  114. __u8 *data)
  115. {
  116. nfcf_poll->bit_rate = *data++;
  117. nfcf_poll->sensf_res_len = min_t(__u8, *data++, NFC_SENSF_RES_MAXSIZE);
  118. pr_debug("bit_rate %d, sensf_res_len %d\n",
  119. nfcf_poll->bit_rate, nfcf_poll->sensf_res_len);
  120. memcpy(nfcf_poll->sensf_res, data, nfcf_poll->sensf_res_len);
  121. data += nfcf_poll->sensf_res_len;
  122. return data;
  123. }
  124. static int nci_add_new_protocol(struct nci_dev *ndev,
  125. struct nfc_target *target,
  126. __u8 rf_protocol,
  127. __u8 rf_tech_and_mode,
  128. void *params)
  129. {
  130. struct rf_tech_specific_params_nfca_poll *nfca_poll;
  131. struct rf_tech_specific_params_nfcb_poll *nfcb_poll;
  132. struct rf_tech_specific_params_nfcf_poll *nfcf_poll;
  133. __u32 protocol;
  134. if (rf_protocol == NCI_RF_PROTOCOL_T2T)
  135. protocol = NFC_PROTO_MIFARE_MASK;
  136. else if (rf_protocol == NCI_RF_PROTOCOL_ISO_DEP)
  137. if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE)
  138. protocol = NFC_PROTO_ISO14443_MASK;
  139. else
  140. protocol = NFC_PROTO_ISO14443_B_MASK;
  141. else if (rf_protocol == NCI_RF_PROTOCOL_T3T)
  142. protocol = NFC_PROTO_FELICA_MASK;
  143. else if (rf_protocol == NCI_RF_PROTOCOL_NFC_DEP)
  144. protocol = NFC_PROTO_NFC_DEP_MASK;
  145. else
  146. protocol = 0;
  147. if (!(protocol & ndev->poll_prots)) {
  148. pr_err("the target found does not have the desired protocol\n");
  149. return -EPROTO;
  150. }
  151. if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE) {
  152. nfca_poll = (struct rf_tech_specific_params_nfca_poll *)params;
  153. target->sens_res = nfca_poll->sens_res;
  154. target->sel_res = nfca_poll->sel_res;
  155. target->nfcid1_len = nfca_poll->nfcid1_len;
  156. if (target->nfcid1_len > 0) {
  157. memcpy(target->nfcid1, nfca_poll->nfcid1,
  158. target->nfcid1_len);
  159. }
  160. } else if (rf_tech_and_mode == NCI_NFC_B_PASSIVE_POLL_MODE) {
  161. nfcb_poll = (struct rf_tech_specific_params_nfcb_poll *)params;
  162. target->sensb_res_len = nfcb_poll->sensb_res_len;
  163. if (target->sensb_res_len > 0) {
  164. memcpy(target->sensb_res, nfcb_poll->sensb_res,
  165. target->sensb_res_len);
  166. }
  167. } else if (rf_tech_and_mode == NCI_NFC_F_PASSIVE_POLL_MODE) {
  168. nfcf_poll = (struct rf_tech_specific_params_nfcf_poll *)params;
  169. target->sensf_res_len = nfcf_poll->sensf_res_len;
  170. if (target->sensf_res_len > 0) {
  171. memcpy(target->sensf_res, nfcf_poll->sensf_res,
  172. target->sensf_res_len);
  173. }
  174. } else {
  175. pr_err("unsupported rf_tech_and_mode 0x%x\n", rf_tech_and_mode);
  176. return -EPROTO;
  177. }
  178. target->supported_protocols |= protocol;
  179. pr_debug("protocol 0x%x\n", protocol);
  180. return 0;
  181. }
  182. static void nci_add_new_target(struct nci_dev *ndev,
  183. struct nci_rf_discover_ntf *ntf)
  184. {
  185. struct nfc_target *target;
  186. int i, rc;
  187. for (i = 0; i < ndev->n_targets; i++) {
  188. target = &ndev->targets[i];
  189. if (target->logical_idx == ntf->rf_discovery_id) {
  190. /* This target already exists, add the new protocol */
  191. nci_add_new_protocol(ndev, target, ntf->rf_protocol,
  192. ntf->rf_tech_and_mode,
  193. &ntf->rf_tech_specific_params);
  194. return;
  195. }
  196. }
  197. /* This is a new target, check if we've enough room */
  198. if (ndev->n_targets == NCI_MAX_DISCOVERED_TARGETS) {
  199. pr_debug("not enough room, ignoring new target...\n");
  200. return;
  201. }
  202. target = &ndev->targets[ndev->n_targets];
  203. rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
  204. ntf->rf_tech_and_mode,
  205. &ntf->rf_tech_specific_params);
  206. if (!rc) {
  207. target->logical_idx = ntf->rf_discovery_id;
  208. ndev->n_targets++;
  209. pr_debug("logical idx %d, n_targets %d\n", target->logical_idx,
  210. ndev->n_targets);
  211. }
  212. }
  213. void nci_clear_target_list(struct nci_dev *ndev)
  214. {
  215. memset(ndev->targets, 0,
  216. (sizeof(struct nfc_target)*NCI_MAX_DISCOVERED_TARGETS));
  217. ndev->n_targets = 0;
  218. }
  219. static void nci_rf_discover_ntf_packet(struct nci_dev *ndev,
  220. struct sk_buff *skb)
  221. {
  222. struct nci_rf_discover_ntf ntf;
  223. __u8 *data = skb->data;
  224. bool add_target = true;
  225. ntf.rf_discovery_id = *data++;
  226. ntf.rf_protocol = *data++;
  227. ntf.rf_tech_and_mode = *data++;
  228. ntf.rf_tech_specific_params_len = *data++;
  229. pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
  230. pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
  231. pr_debug("rf_tech_and_mode 0x%x\n", ntf.rf_tech_and_mode);
  232. pr_debug("rf_tech_specific_params_len %d\n",
  233. ntf.rf_tech_specific_params_len);
  234. if (ntf.rf_tech_specific_params_len > 0) {
  235. switch (ntf.rf_tech_and_mode) {
  236. case NCI_NFC_A_PASSIVE_POLL_MODE:
  237. data = nci_extract_rf_params_nfca_passive_poll(ndev,
  238. &(ntf.rf_tech_specific_params.nfca_poll), data);
  239. break;
  240. case NCI_NFC_B_PASSIVE_POLL_MODE:
  241. data = nci_extract_rf_params_nfcb_passive_poll(ndev,
  242. &(ntf.rf_tech_specific_params.nfcb_poll), data);
  243. break;
  244. case NCI_NFC_F_PASSIVE_POLL_MODE:
  245. data = nci_extract_rf_params_nfcf_passive_poll(ndev,
  246. &(ntf.rf_tech_specific_params.nfcf_poll), data);
  247. break;
  248. default:
  249. pr_err("unsupported rf_tech_and_mode 0x%x\n",
  250. ntf.rf_tech_and_mode);
  251. data += ntf.rf_tech_specific_params_len;
  252. add_target = false;
  253. }
  254. }
  255. ntf.ntf_type = *data++;
  256. pr_debug("ntf_type %d\n", ntf.ntf_type);
  257. if (add_target == true)
  258. nci_add_new_target(ndev, &ntf);
  259. if (ntf.ntf_type == NCI_DISCOVER_NTF_TYPE_MORE) {
  260. atomic_set(&ndev->state, NCI_W4_ALL_DISCOVERIES);
  261. } else {
  262. atomic_set(&ndev->state, NCI_W4_HOST_SELECT);
  263. nfc_targets_found(ndev->nfc_dev, ndev->targets,
  264. ndev->n_targets);
  265. }
  266. }
  267. static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev,
  268. struct nci_rf_intf_activated_ntf *ntf, __u8 *data)
  269. {
  270. struct activation_params_nfca_poll_iso_dep *nfca_poll;
  271. struct activation_params_nfcb_poll_iso_dep *nfcb_poll;
  272. switch (ntf->activation_rf_tech_and_mode) {
  273. case NCI_NFC_A_PASSIVE_POLL_MODE:
  274. nfca_poll = &ntf->activation_params.nfca_poll_iso_dep;
  275. nfca_poll->rats_res_len = min_t(__u8, *data++, 20);
  276. pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len);
  277. if (nfca_poll->rats_res_len > 0) {
  278. memcpy(nfca_poll->rats_res,
  279. data, nfca_poll->rats_res_len);
  280. }
  281. break;
  282. case NCI_NFC_B_PASSIVE_POLL_MODE:
  283. nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep;
  284. nfcb_poll->attrib_res_len = min_t(__u8, *data++, 50);
  285. pr_debug("attrib_res_len %d\n", nfcb_poll->attrib_res_len);
  286. if (nfcb_poll->attrib_res_len > 0) {
  287. memcpy(nfcb_poll->attrib_res,
  288. data, nfcb_poll->attrib_res_len);
  289. }
  290. break;
  291. default:
  292. pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
  293. ntf->activation_rf_tech_and_mode);
  294. return NCI_STATUS_RF_PROTOCOL_ERROR;
  295. }
  296. return NCI_STATUS_OK;
  297. }
  298. static int nci_extract_activation_params_nfc_dep(struct nci_dev *ndev,
  299. struct nci_rf_intf_activated_ntf *ntf, __u8 *data)
  300. {
  301. struct activation_params_poll_nfc_dep *poll;
  302. int i;
  303. switch (ntf->activation_rf_tech_and_mode) {
  304. case NCI_NFC_A_PASSIVE_POLL_MODE:
  305. case NCI_NFC_F_PASSIVE_POLL_MODE:
  306. poll = &ntf->activation_params.poll_nfc_dep;
  307. poll->atr_res_len = min_t(__u8, *data++, 63);
  308. pr_debug("atr_res_len %d\n", poll->atr_res_len);
  309. if (poll->atr_res_len > 0) {
  310. for (i = 0; i < poll->atr_res_len; i++)
  311. poll->atr_res[poll->atr_res_len-1-i] = data[i];
  312. }
  313. break;
  314. default:
  315. pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
  316. ntf->activation_rf_tech_and_mode);
  317. return NCI_STATUS_RF_PROTOCOL_ERROR;
  318. }
  319. return NCI_STATUS_OK;
  320. }
  321. static void nci_target_auto_activated(struct nci_dev *ndev,
  322. struct nci_rf_intf_activated_ntf *ntf)
  323. {
  324. struct nfc_target *target;
  325. int rc;
  326. target = &ndev->targets[ndev->n_targets];
  327. rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
  328. ntf->activation_rf_tech_and_mode,
  329. &ntf->rf_tech_specific_params);
  330. if (rc)
  331. return;
  332. target->logical_idx = ntf->rf_discovery_id;
  333. ndev->n_targets++;
  334. pr_debug("logical idx %d, n_targets %d\n",
  335. target->logical_idx, ndev->n_targets);
  336. nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets);
  337. }
  338. static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
  339. struct sk_buff *skb)
  340. {
  341. struct nci_rf_intf_activated_ntf ntf;
  342. __u8 *data = skb->data;
  343. int err = NCI_STATUS_OK;
  344. ntf.rf_discovery_id = *data++;
  345. ntf.rf_interface = *data++;
  346. ntf.rf_protocol = *data++;
  347. ntf.activation_rf_tech_and_mode = *data++;
  348. ntf.max_data_pkt_payload_size = *data++;
  349. ntf.initial_num_credits = *data++;
  350. ntf.rf_tech_specific_params_len = *data++;
  351. pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
  352. pr_debug("rf_interface 0x%x\n", ntf.rf_interface);
  353. pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
  354. pr_debug("activation_rf_tech_and_mode 0x%x\n",
  355. ntf.activation_rf_tech_and_mode);
  356. pr_debug("max_data_pkt_payload_size 0x%x\n",
  357. ntf.max_data_pkt_payload_size);
  358. pr_debug("initial_num_credits 0x%x\n",
  359. ntf.initial_num_credits);
  360. pr_debug("rf_tech_specific_params_len %d\n",
  361. ntf.rf_tech_specific_params_len);
  362. if (ntf.rf_tech_specific_params_len > 0) {
  363. switch (ntf.activation_rf_tech_and_mode) {
  364. case NCI_NFC_A_PASSIVE_POLL_MODE:
  365. data = nci_extract_rf_params_nfca_passive_poll(ndev,
  366. &(ntf.rf_tech_specific_params.nfca_poll), data);
  367. break;
  368. case NCI_NFC_B_PASSIVE_POLL_MODE:
  369. data = nci_extract_rf_params_nfcb_passive_poll(ndev,
  370. &(ntf.rf_tech_specific_params.nfcb_poll), data);
  371. break;
  372. case NCI_NFC_F_PASSIVE_POLL_MODE:
  373. data = nci_extract_rf_params_nfcf_passive_poll(ndev,
  374. &(ntf.rf_tech_specific_params.nfcf_poll), data);
  375. break;
  376. default:
  377. pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
  378. ntf.activation_rf_tech_and_mode);
  379. err = NCI_STATUS_RF_PROTOCOL_ERROR;
  380. goto exit;
  381. }
  382. }
  383. ntf.data_exch_rf_tech_and_mode = *data++;
  384. ntf.data_exch_tx_bit_rate = *data++;
  385. ntf.data_exch_rx_bit_rate = *data++;
  386. ntf.activation_params_len = *data++;
  387. pr_debug("data_exch_rf_tech_and_mode 0x%x\n",
  388. ntf.data_exch_rf_tech_and_mode);
  389. pr_debug("data_exch_tx_bit_rate 0x%x\n", ntf.data_exch_tx_bit_rate);
  390. pr_debug("data_exch_rx_bit_rate 0x%x\n", ntf.data_exch_rx_bit_rate);
  391. pr_debug("activation_params_len %d\n", ntf.activation_params_len);
  392. if (ntf.activation_params_len > 0) {
  393. switch (ntf.rf_interface) {
  394. case NCI_RF_INTERFACE_ISO_DEP:
  395. err = nci_extract_activation_params_iso_dep(ndev,
  396. &ntf, data);
  397. break;
  398. case NCI_RF_INTERFACE_NFC_DEP:
  399. err = nci_extract_activation_params_nfc_dep(ndev,
  400. &ntf, data);
  401. break;
  402. case NCI_RF_INTERFACE_FRAME:
  403. /* no activation params */
  404. break;
  405. default:
  406. pr_err("unsupported rf_interface 0x%x\n",
  407. ntf.rf_interface);
  408. err = NCI_STATUS_RF_PROTOCOL_ERROR;
  409. break;
  410. }
  411. }
  412. exit:
  413. if (err == NCI_STATUS_OK) {
  414. ndev->max_data_pkt_payload_size = ntf.max_data_pkt_payload_size;
  415. ndev->initial_num_credits = ntf.initial_num_credits;
  416. /* set the available credits to initial value */
  417. atomic_set(&ndev->credits_cnt, ndev->initial_num_credits);
  418. /* store general bytes to be reported later in dep_link_up */
  419. if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) {
  420. ndev->remote_gb_len = 0;
  421. if (ntf.activation_params_len > 0) {
  422. /* ATR_RES general bytes at offset 15 */
  423. ndev->remote_gb_len = min_t(__u8,
  424. (ntf.activation_params
  425. .poll_nfc_dep.atr_res_len
  426. - NFC_ATR_RES_GT_OFFSET),
  427. NFC_MAX_GT_LEN);
  428. memcpy(ndev->remote_gb,
  429. (ntf.activation_params.poll_nfc_dep
  430. .atr_res + NFC_ATR_RES_GT_OFFSET),
  431. ndev->remote_gb_len);
  432. }
  433. }
  434. }
  435. if (atomic_read(&ndev->state) == NCI_DISCOVERY) {
  436. /* A single target was found and activated automatically */
  437. atomic_set(&ndev->state, NCI_POLL_ACTIVE);
  438. if (err == NCI_STATUS_OK)
  439. nci_target_auto_activated(ndev, &ntf);
  440. } else { /* ndev->state == NCI_W4_HOST_SELECT */
  441. /* A selected target was activated, so complete the request */
  442. atomic_set(&ndev->state, NCI_POLL_ACTIVE);
  443. nci_req_complete(ndev, err);
  444. }
  445. }
  446. static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
  447. struct sk_buff *skb)
  448. {
  449. struct nci_rf_deactivate_ntf *ntf = (void *) skb->data;
  450. pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);
  451. /* drop tx data queue */
  452. skb_queue_purge(&ndev->tx_q);
  453. /* drop partial rx data packet */
  454. if (ndev->rx_data_reassembly) {
  455. kfree_skb(ndev->rx_data_reassembly);
  456. ndev->rx_data_reassembly = NULL;
  457. }
  458. /* complete the data exchange transaction, if exists */
  459. if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
  460. nci_data_exchange_complete(ndev, NULL, -EIO);
  461. nci_clear_target_list(ndev);
  462. atomic_set(&ndev->state, NCI_IDLE);
  463. nci_req_complete(ndev, NCI_STATUS_OK);
  464. }
  465. void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
  466. {
  467. __u16 ntf_opcode = nci_opcode(skb->data);
  468. pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
  469. nci_pbf(skb->data),
  470. nci_opcode_gid(ntf_opcode),
  471. nci_opcode_oid(ntf_opcode),
  472. nci_plen(skb->data));
  473. /* strip the nci control header */
  474. skb_pull(skb, NCI_CTRL_HDR_SIZE);
  475. switch (ntf_opcode) {
  476. case NCI_OP_CORE_CONN_CREDITS_NTF:
  477. nci_core_conn_credits_ntf_packet(ndev, skb);
  478. break;
  479. case NCI_OP_CORE_GENERIC_ERROR_NTF:
  480. nci_core_generic_error_ntf_packet(ndev, skb);
  481. break;
  482. case NCI_OP_CORE_INTF_ERROR_NTF:
  483. nci_core_conn_intf_error_ntf_packet(ndev, skb);
  484. break;
  485. case NCI_OP_RF_DISCOVER_NTF:
  486. nci_rf_discover_ntf_packet(ndev, skb);
  487. break;
  488. case NCI_OP_RF_INTF_ACTIVATED_NTF:
  489. nci_rf_intf_activated_ntf_packet(ndev, skb);
  490. break;
  491. case NCI_OP_RF_DEACTIVATE_NTF:
  492. nci_rf_deactivate_ntf_packet(ndev, skb);
  493. break;
  494. default:
  495. pr_err("unknown ntf opcode 0x%x\n", ntf_opcode);
  496. break;
  497. }
  498. kfree_skb(skb);
  499. }