2 * The NFC Controller Interface is the communication protocol between an
3 * NFC Controller (NFCC) and a Device Host (DH).
5 * Copyright (C) 2014 Marvell International Ltd.
6 * Copyright (C) 2011 Texas Instruments, Inc.
8 * Written by Ilan Elias <ilane@ti.com>
11 * This file is based on hci_event.c, which was written
12 * by Maxim Krasnyansky.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2
16 * as published by the Free Software Foundation
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <http://www.gnu.org/licenses/>.
28 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
30 #include <linux/types.h>
31 #include <linux/interrupt.h>
32 #include <linux/bitops.h>
33 #include <linux/skbuff.h>
36 #include <net/nfc/nci.h>
37 #include <net/nfc/nci_core.h>
38 #include <linux/nfc.h>
40 /* Handle NCI Notification packets */
42 static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
45 struct nci_core_conn_credit_ntf *ntf = (void *) skb->data;
46 struct nci_conn_info *conn_info;
49 pr_debug("num_entries %d\n", ntf->num_entries);
51 if (ntf->num_entries > NCI_MAX_NUM_CONN)
52 ntf->num_entries = NCI_MAX_NUM_CONN;
54 /* update the credits */
55 for (i = 0; i < ntf->num_entries; i++) {
56 ntf->conn_entries[i].conn_id =
57 nci_conn_id(&ntf->conn_entries[i].conn_id);
59 pr_debug("entry[%d]: conn_id %d, credits %d\n",
60 i, ntf->conn_entries[i].conn_id,
61 ntf->conn_entries[i].credits);
63 conn_info = nci_get_conn_info_by_conn_id(ndev,
64 ntf->conn_entries[i].conn_id);
68 atomic_add(ntf->conn_entries[i].credits,
69 &conn_info->credits_cnt);
72 /* trigger the next tx */
73 if (!skb_queue_empty(&ndev->tx_q))
74 queue_work(ndev->tx_wq, &ndev->tx_work);
77 static void nci_core_generic_error_ntf_packet(struct nci_dev *ndev,
80 __u8 status = skb->data[0];
82 pr_debug("status 0x%x\n", status);
84 if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) {
85 /* Activation failed, so complete the request
86 (the state remains the same) */
87 nci_req_complete(ndev, status);
91 static void nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev,
94 struct nci_core_intf_error_ntf *ntf = (void *) skb->data;
96 ntf->conn_id = nci_conn_id(&ntf->conn_id);
98 pr_debug("status 0x%x, conn_id %d\n", ntf->status, ntf->conn_id);
100 /* complete the data exchange transaction, if exists */
101 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
102 nci_data_exchange_complete(ndev, NULL, ntf->conn_id, -EIO);
105 static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev,
106 struct rf_tech_specific_params_nfca_poll *nfca_poll,
109 nfca_poll->sens_res = __le16_to_cpu(*((__le16 *)data));
112 nfca_poll->nfcid1_len = min_t(__u8, *data++, NFC_NFCID1_MAXSIZE);
114 pr_debug("sens_res 0x%x, nfcid1_len %d\n",
115 nfca_poll->sens_res, nfca_poll->nfcid1_len);
117 memcpy(nfca_poll->nfcid1, data, nfca_poll->nfcid1_len);
118 data += nfca_poll->nfcid1_len;
120 nfca_poll->sel_res_len = *data++;
122 if (nfca_poll->sel_res_len != 0)
123 nfca_poll->sel_res = *data++;
125 pr_debug("sel_res_len %d, sel_res 0x%x\n",
126 nfca_poll->sel_res_len,
132 static __u8 *nci_extract_rf_params_nfcb_passive_poll(struct nci_dev *ndev,
133 struct rf_tech_specific_params_nfcb_poll *nfcb_poll,
136 nfcb_poll->sensb_res_len = min_t(__u8, *data++, NFC_SENSB_RES_MAXSIZE);
138 pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len);
140 memcpy(nfcb_poll->sensb_res, data, nfcb_poll->sensb_res_len);
141 data += nfcb_poll->sensb_res_len;
146 static __u8 *nci_extract_rf_params_nfcf_passive_poll(struct nci_dev *ndev,
147 struct rf_tech_specific_params_nfcf_poll *nfcf_poll,
150 nfcf_poll->bit_rate = *data++;
151 nfcf_poll->sensf_res_len = min_t(__u8, *data++, NFC_SENSF_RES_MAXSIZE);
153 pr_debug("bit_rate %d, sensf_res_len %d\n",
154 nfcf_poll->bit_rate, nfcf_poll->sensf_res_len);
156 memcpy(nfcf_poll->sensf_res, data, nfcf_poll->sensf_res_len);
157 data += nfcf_poll->sensf_res_len;
162 static __u8 *nci_extract_rf_params_nfcv_passive_poll(struct nci_dev *ndev,
163 struct rf_tech_specific_params_nfcv_poll *nfcv_poll,
167 nfcv_poll->dsfid = *data++;
168 memcpy(nfcv_poll->uid, data, NFC_ISO15693_UID_MAXSIZE);
169 data += NFC_ISO15693_UID_MAXSIZE;
173 static __u8 *nci_extract_rf_params_nfcf_passive_listen(struct nci_dev *ndev,
174 struct rf_tech_specific_params_nfcf_listen *nfcf_listen,
177 nfcf_listen->local_nfcid2_len = min_t(__u8, *data++,
179 memcpy(nfcf_listen->local_nfcid2, data, nfcf_listen->local_nfcid2_len);
180 data += nfcf_listen->local_nfcid2_len;
185 static __u32 nci_get_prop_rf_protocol(struct nci_dev *ndev, __u8 rf_protocol)
187 if (ndev->ops->get_rfprotocol)
188 return ndev->ops->get_rfprotocol(ndev, rf_protocol);
192 static int nci_add_new_protocol(struct nci_dev *ndev,
193 struct nfc_target *target,
195 __u8 rf_tech_and_mode,
198 struct rf_tech_specific_params_nfca_poll *nfca_poll;
199 struct rf_tech_specific_params_nfcb_poll *nfcb_poll;
200 struct rf_tech_specific_params_nfcf_poll *nfcf_poll;
201 struct rf_tech_specific_params_nfcv_poll *nfcv_poll;
204 if (rf_protocol == NCI_RF_PROTOCOL_T1T)
205 protocol = NFC_PROTO_JEWEL_MASK;
206 else if (rf_protocol == NCI_RF_PROTOCOL_T2T)
207 protocol = NFC_PROTO_MIFARE_MASK;
208 else if (rf_protocol == NCI_RF_PROTOCOL_ISO_DEP)
209 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE)
210 protocol = NFC_PROTO_ISO14443_MASK;
212 protocol = NFC_PROTO_ISO14443_B_MASK;
213 else if (rf_protocol == NCI_RF_PROTOCOL_T3T)
214 protocol = NFC_PROTO_FELICA_MASK;
215 else if (rf_protocol == NCI_RF_PROTOCOL_NFC_DEP)
216 protocol = NFC_PROTO_NFC_DEP_MASK;
217 else if (rf_protocol == NCI_RF_PROTOCOL_T5T)
218 protocol = NFC_PROTO_ISO15693_MASK;
220 protocol = nci_get_prop_rf_protocol(ndev, rf_protocol);
222 if (!(protocol & ndev->poll_prots)) {
223 pr_err("the target found does not have the desired protocol\n");
227 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE) {
228 nfca_poll = (struct rf_tech_specific_params_nfca_poll *)params;
230 target->sens_res = nfca_poll->sens_res;
231 target->sel_res = nfca_poll->sel_res;
232 target->nfcid1_len = nfca_poll->nfcid1_len;
233 if (target->nfcid1_len > ARRAY_SIZE(target->nfcid1))
235 if (target->nfcid1_len > 0) {
236 memcpy(target->nfcid1, nfca_poll->nfcid1,
239 } else if (rf_tech_and_mode == NCI_NFC_B_PASSIVE_POLL_MODE) {
240 nfcb_poll = (struct rf_tech_specific_params_nfcb_poll *)params;
242 target->sensb_res_len = nfcb_poll->sensb_res_len;
243 if (target->sensb_res_len > ARRAY_SIZE(target->sensb_res))
245 if (target->sensb_res_len > 0) {
246 memcpy(target->sensb_res, nfcb_poll->sensb_res,
247 target->sensb_res_len);
249 } else if (rf_tech_and_mode == NCI_NFC_F_PASSIVE_POLL_MODE) {
250 nfcf_poll = (struct rf_tech_specific_params_nfcf_poll *)params;
252 target->sensf_res_len = nfcf_poll->sensf_res_len;
253 if (target->sensf_res_len > ARRAY_SIZE(target->sensf_res))
255 if (target->sensf_res_len > 0) {
256 memcpy(target->sensf_res, nfcf_poll->sensf_res,
257 target->sensf_res_len);
259 } else if (rf_tech_and_mode == NCI_NFC_V_PASSIVE_POLL_MODE) {
260 nfcv_poll = (struct rf_tech_specific_params_nfcv_poll *)params;
262 target->is_iso15693 = 1;
263 target->iso15693_dsfid = nfcv_poll->dsfid;
264 memcpy(target->iso15693_uid, nfcv_poll->uid, NFC_ISO15693_UID_MAXSIZE);
266 pr_err("unsupported rf_tech_and_mode 0x%x\n", rf_tech_and_mode);
270 target->supported_protocols |= protocol;
272 pr_debug("protocol 0x%x\n", protocol);
277 static void nci_add_new_target(struct nci_dev *ndev,
278 struct nci_rf_discover_ntf *ntf)
280 struct nfc_target *target;
283 for (i = 0; i < ndev->n_targets; i++) {
284 target = &ndev->targets[i];
285 if (target->logical_idx == ntf->rf_discovery_id) {
286 /* This target already exists, add the new protocol */
287 nci_add_new_protocol(ndev, target, ntf->rf_protocol,
288 ntf->rf_tech_and_mode,
289 &ntf->rf_tech_specific_params);
294 /* This is a new target, check if we've enough room */
295 if (ndev->n_targets == NCI_MAX_DISCOVERED_TARGETS) {
296 pr_debug("not enough room, ignoring new target...\n");
300 target = &ndev->targets[ndev->n_targets];
302 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
303 ntf->rf_tech_and_mode,
304 &ntf->rf_tech_specific_params);
306 target->logical_idx = ntf->rf_discovery_id;
309 pr_debug("logical idx %d, n_targets %d\n", target->logical_idx,
314 void nci_clear_target_list(struct nci_dev *ndev)
316 memset(ndev->targets, 0,
317 (sizeof(struct nfc_target)*NCI_MAX_DISCOVERED_TARGETS));
322 static void nci_rf_discover_ntf_packet(struct nci_dev *ndev,
325 struct nci_rf_discover_ntf ntf;
326 __u8 *data = skb->data;
327 bool add_target = true;
329 ntf.rf_discovery_id = *data++;
330 ntf.rf_protocol = *data++;
331 ntf.rf_tech_and_mode = *data++;
332 ntf.rf_tech_specific_params_len = *data++;
334 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
335 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
336 pr_debug("rf_tech_and_mode 0x%x\n", ntf.rf_tech_and_mode);
337 pr_debug("rf_tech_specific_params_len %d\n",
338 ntf.rf_tech_specific_params_len);
340 if (ntf.rf_tech_specific_params_len > 0) {
341 switch (ntf.rf_tech_and_mode) {
342 case NCI_NFC_A_PASSIVE_POLL_MODE:
343 data = nci_extract_rf_params_nfca_passive_poll(ndev,
344 &(ntf.rf_tech_specific_params.nfca_poll), data);
347 case NCI_NFC_B_PASSIVE_POLL_MODE:
348 data = nci_extract_rf_params_nfcb_passive_poll(ndev,
349 &(ntf.rf_tech_specific_params.nfcb_poll), data);
352 case NCI_NFC_F_PASSIVE_POLL_MODE:
353 data = nci_extract_rf_params_nfcf_passive_poll(ndev,
354 &(ntf.rf_tech_specific_params.nfcf_poll), data);
357 case NCI_NFC_V_PASSIVE_POLL_MODE:
358 data = nci_extract_rf_params_nfcv_passive_poll(ndev,
359 &(ntf.rf_tech_specific_params.nfcv_poll), data);
363 pr_err("unsupported rf_tech_and_mode 0x%x\n",
364 ntf.rf_tech_and_mode);
365 data += ntf.rf_tech_specific_params_len;
370 ntf.ntf_type = *data++;
371 pr_debug("ntf_type %d\n", ntf.ntf_type);
373 if (add_target == true)
374 nci_add_new_target(ndev, &ntf);
376 if (ntf.ntf_type == NCI_DISCOVER_NTF_TYPE_MORE) {
377 atomic_set(&ndev->state, NCI_W4_ALL_DISCOVERIES);
379 atomic_set(&ndev->state, NCI_W4_HOST_SELECT);
380 nfc_targets_found(ndev->nfc_dev, ndev->targets,
385 static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev,
386 struct nci_rf_intf_activated_ntf *ntf, __u8 *data)
388 struct activation_params_nfca_poll_iso_dep *nfca_poll;
389 struct activation_params_nfcb_poll_iso_dep *nfcb_poll;
391 switch (ntf->activation_rf_tech_and_mode) {
392 case NCI_NFC_A_PASSIVE_POLL_MODE:
393 nfca_poll = &ntf->activation_params.nfca_poll_iso_dep;
394 nfca_poll->rats_res_len = min_t(__u8, *data++, 20);
395 pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len);
396 if (nfca_poll->rats_res_len > 0) {
397 memcpy(nfca_poll->rats_res,
398 data, nfca_poll->rats_res_len);
402 case NCI_NFC_B_PASSIVE_POLL_MODE:
403 nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep;
404 nfcb_poll->attrib_res_len = min_t(__u8, *data++, 50);
405 pr_debug("attrib_res_len %d\n", nfcb_poll->attrib_res_len);
406 if (nfcb_poll->attrib_res_len > 0) {
407 memcpy(nfcb_poll->attrib_res,
408 data, nfcb_poll->attrib_res_len);
413 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
414 ntf->activation_rf_tech_and_mode);
415 return NCI_STATUS_RF_PROTOCOL_ERROR;
418 return NCI_STATUS_OK;
421 static int nci_extract_activation_params_nfc_dep(struct nci_dev *ndev,
422 struct nci_rf_intf_activated_ntf *ntf, __u8 *data)
424 struct activation_params_poll_nfc_dep *poll;
425 struct activation_params_listen_nfc_dep *listen;
427 switch (ntf->activation_rf_tech_and_mode) {
428 case NCI_NFC_A_PASSIVE_POLL_MODE:
429 case NCI_NFC_F_PASSIVE_POLL_MODE:
430 poll = &ntf->activation_params.poll_nfc_dep;
431 poll->atr_res_len = min_t(__u8, *data++,
432 NFC_ATR_RES_MAXSIZE - 2);
433 pr_debug("atr_res_len %d\n", poll->atr_res_len);
434 if (poll->atr_res_len > 0)
435 memcpy(poll->atr_res, data, poll->atr_res_len);
438 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
439 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
440 listen = &ntf->activation_params.listen_nfc_dep;
441 listen->atr_req_len = min_t(__u8, *data++,
442 NFC_ATR_REQ_MAXSIZE - 2);
443 pr_debug("atr_req_len %d\n", listen->atr_req_len);
444 if (listen->atr_req_len > 0)
445 memcpy(listen->atr_req, data, listen->atr_req_len);
449 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
450 ntf->activation_rf_tech_and_mode);
451 return NCI_STATUS_RF_PROTOCOL_ERROR;
454 return NCI_STATUS_OK;
457 static void nci_target_auto_activated(struct nci_dev *ndev,
458 struct nci_rf_intf_activated_ntf *ntf)
460 struct nfc_target *target;
463 target = &ndev->targets[ndev->n_targets];
465 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
466 ntf->activation_rf_tech_and_mode,
467 &ntf->rf_tech_specific_params);
471 target->logical_idx = ntf->rf_discovery_id;
474 pr_debug("logical idx %d, n_targets %d\n",
475 target->logical_idx, ndev->n_targets);
477 nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets);
480 static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
481 struct nci_rf_intf_activated_ntf *ntf)
483 ndev->remote_gb_len = 0;
485 if (ntf->activation_params_len <= 0)
486 return NCI_STATUS_OK;
488 switch (ntf->activation_rf_tech_and_mode) {
489 case NCI_NFC_A_PASSIVE_POLL_MODE:
490 case NCI_NFC_F_PASSIVE_POLL_MODE:
491 ndev->remote_gb_len = min_t(__u8,
492 (ntf->activation_params.poll_nfc_dep.atr_res_len
493 - NFC_ATR_RES_GT_OFFSET),
494 NFC_ATR_RES_GB_MAXSIZE);
495 memcpy(ndev->remote_gb,
496 (ntf->activation_params.poll_nfc_dep.atr_res
497 + NFC_ATR_RES_GT_OFFSET),
498 ndev->remote_gb_len);
501 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
502 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
503 ndev->remote_gb_len = min_t(__u8,
504 (ntf->activation_params.listen_nfc_dep.atr_req_len
505 - NFC_ATR_REQ_GT_OFFSET),
506 NFC_ATR_REQ_GB_MAXSIZE);
507 memcpy(ndev->remote_gb,
508 (ntf->activation_params.listen_nfc_dep.atr_req
509 + NFC_ATR_REQ_GT_OFFSET),
510 ndev->remote_gb_len);
514 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
515 ntf->activation_rf_tech_and_mode);
516 return NCI_STATUS_RF_PROTOCOL_ERROR;
519 return NCI_STATUS_OK;
522 static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
525 struct nci_conn_info *conn_info;
526 struct nci_rf_intf_activated_ntf ntf;
527 __u8 *data = skb->data;
528 int err = NCI_STATUS_OK;
530 ntf.rf_discovery_id = *data++;
531 ntf.rf_interface = *data++;
532 ntf.rf_protocol = *data++;
533 ntf.activation_rf_tech_and_mode = *data++;
534 ntf.max_data_pkt_payload_size = *data++;
535 ntf.initial_num_credits = *data++;
536 ntf.rf_tech_specific_params_len = *data++;
538 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
539 pr_debug("rf_interface 0x%x\n", ntf.rf_interface);
540 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
541 pr_debug("activation_rf_tech_and_mode 0x%x\n",
542 ntf.activation_rf_tech_and_mode);
543 pr_debug("max_data_pkt_payload_size 0x%x\n",
544 ntf.max_data_pkt_payload_size);
545 pr_debug("initial_num_credits 0x%x\n",
546 ntf.initial_num_credits);
547 pr_debug("rf_tech_specific_params_len %d\n",
548 ntf.rf_tech_specific_params_len);
550 /* If this contains a value of 0x00 (NFCEE Direct RF
551 * Interface) then all following parameters SHALL contain a
552 * value of 0 and SHALL be ignored.
554 if (ntf.rf_interface == NCI_RF_INTERFACE_NFCEE_DIRECT)
557 if (ntf.rf_tech_specific_params_len > 0) {
558 switch (ntf.activation_rf_tech_and_mode) {
559 case NCI_NFC_A_PASSIVE_POLL_MODE:
560 data = nci_extract_rf_params_nfca_passive_poll(ndev,
561 &(ntf.rf_tech_specific_params.nfca_poll), data);
564 case NCI_NFC_B_PASSIVE_POLL_MODE:
565 data = nci_extract_rf_params_nfcb_passive_poll(ndev,
566 &(ntf.rf_tech_specific_params.nfcb_poll), data);
569 case NCI_NFC_F_PASSIVE_POLL_MODE:
570 data = nci_extract_rf_params_nfcf_passive_poll(ndev,
571 &(ntf.rf_tech_specific_params.nfcf_poll), data);
574 case NCI_NFC_V_PASSIVE_POLL_MODE:
575 data = nci_extract_rf_params_nfcv_passive_poll(ndev,
576 &(ntf.rf_tech_specific_params.nfcv_poll), data);
579 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
580 /* no RF technology specific parameters */
583 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
584 data = nci_extract_rf_params_nfcf_passive_listen(ndev,
585 &(ntf.rf_tech_specific_params.nfcf_listen),
590 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
591 ntf.activation_rf_tech_and_mode);
592 err = NCI_STATUS_RF_PROTOCOL_ERROR;
597 ntf.data_exch_rf_tech_and_mode = *data++;
598 ntf.data_exch_tx_bit_rate = *data++;
599 ntf.data_exch_rx_bit_rate = *data++;
600 ntf.activation_params_len = *data++;
602 pr_debug("data_exch_rf_tech_and_mode 0x%x\n",
603 ntf.data_exch_rf_tech_and_mode);
604 pr_debug("data_exch_tx_bit_rate 0x%x\n", ntf.data_exch_tx_bit_rate);
605 pr_debug("data_exch_rx_bit_rate 0x%x\n", ntf.data_exch_rx_bit_rate);
606 pr_debug("activation_params_len %d\n", ntf.activation_params_len);
608 if (ntf.activation_params_len > 0) {
609 switch (ntf.rf_interface) {
610 case NCI_RF_INTERFACE_ISO_DEP:
611 err = nci_extract_activation_params_iso_dep(ndev,
615 case NCI_RF_INTERFACE_NFC_DEP:
616 err = nci_extract_activation_params_nfc_dep(ndev,
620 case NCI_RF_INTERFACE_FRAME:
621 /* no activation params */
625 pr_err("unsupported rf_interface 0x%x\n",
627 err = NCI_STATUS_RF_PROTOCOL_ERROR;
633 if (err == NCI_STATUS_OK) {
634 conn_info = ndev->rf_conn_info;
638 conn_info->max_pkt_payload_len = ntf.max_data_pkt_payload_size;
639 conn_info->initial_num_credits = ntf.initial_num_credits;
641 /* set the available credits to initial value */
642 atomic_set(&conn_info->credits_cnt,
643 conn_info->initial_num_credits);
645 /* store general bytes to be reported later in dep_link_up */
646 if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) {
647 err = nci_store_general_bytes_nfc_dep(ndev, &ntf);
648 if (err != NCI_STATUS_OK)
649 pr_err("unable to store general bytes\n");
653 if (!(ntf.activation_rf_tech_and_mode & NCI_RF_TECH_MODE_LISTEN_MASK)) {
655 if (atomic_read(&ndev->state) == NCI_DISCOVERY) {
656 /* A single target was found and activated
658 atomic_set(&ndev->state, NCI_POLL_ACTIVE);
659 if (err == NCI_STATUS_OK)
660 nci_target_auto_activated(ndev, &ntf);
661 } else { /* ndev->state == NCI_W4_HOST_SELECT */
662 /* A selected target was activated, so complete the
664 atomic_set(&ndev->state, NCI_POLL_ACTIVE);
665 nci_req_complete(ndev, err);
670 atomic_set(&ndev->state, NCI_LISTEN_ACTIVE);
671 if (err == NCI_STATUS_OK &&
672 ntf.rf_protocol == NCI_RF_PROTOCOL_NFC_DEP) {
673 err = nfc_tm_activated(ndev->nfc_dev,
674 NFC_PROTO_NFC_DEP_MASK,
677 ndev->remote_gb_len);
678 if (err != NCI_STATUS_OK)
679 pr_err("error when signaling tm activation\n");
684 static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
687 struct nci_conn_info *conn_info;
688 struct nci_rf_deactivate_ntf *ntf = (void *) skb->data;
690 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);
692 conn_info = ndev->rf_conn_info;
696 /* drop tx data queue */
697 skb_queue_purge(&ndev->tx_q);
699 /* drop partial rx data packet */
700 if (ndev->rx_data_reassembly) {
701 kfree_skb(ndev->rx_data_reassembly);
702 ndev->rx_data_reassembly = NULL;
705 /* complete the data exchange transaction, if exists */
706 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
707 nci_data_exchange_complete(ndev, NULL, NCI_STATIC_RF_CONN_ID,
711 case NCI_DEACTIVATE_TYPE_IDLE_MODE:
712 nci_clear_target_list(ndev);
713 atomic_set(&ndev->state, NCI_IDLE);
715 case NCI_DEACTIVATE_TYPE_SLEEP_MODE:
716 case NCI_DEACTIVATE_TYPE_SLEEP_AF_MODE:
717 atomic_set(&ndev->state, NCI_W4_HOST_SELECT);
719 case NCI_DEACTIVATE_TYPE_DISCOVERY:
720 nci_clear_target_list(ndev);
721 atomic_set(&ndev->state, NCI_DISCOVERY);
725 nci_req_complete(ndev, NCI_STATUS_OK);
728 static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev,
731 u8 status = NCI_STATUS_OK;
732 struct nci_nfcee_discover_ntf *nfcee_ntf =
733 (struct nci_nfcee_discover_ntf *)skb->data;
737 /* NFCForum NCI 9.2.1 HCI Network Specific Handling
738 * If the NFCC supports the HCI Network, it SHALL return one,
739 * and only one, NFCEE_DISCOVER_NTF with a Protocol type of
740 * “HCI Access”, even if the HCI Network contains multiple NFCEEs.
742 ndev->hci_dev->nfcee_id = nfcee_ntf->nfcee_id;
743 ndev->cur_params.id = nfcee_ntf->nfcee_id;
745 nci_req_complete(ndev, status);
748 static void nci_nfcee_action_ntf_packet(struct nci_dev *ndev,
754 void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
756 __u16 ntf_opcode = nci_opcode(skb->data);
758 pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
760 nci_opcode_gid(ntf_opcode),
761 nci_opcode_oid(ntf_opcode),
762 nci_plen(skb->data));
764 /* strip the nci control header */
765 skb_pull(skb, NCI_CTRL_HDR_SIZE);
767 if (nci_opcode_gid(ntf_opcode) == NCI_GID_PROPRIETARY) {
768 if (nci_prop_ntf_packet(ndev, ntf_opcode, skb) == -ENOTSUPP) {
769 pr_err("unsupported ntf opcode 0x%x\n",
776 switch (ntf_opcode) {
777 case NCI_OP_CORE_CONN_CREDITS_NTF:
778 nci_core_conn_credits_ntf_packet(ndev, skb);
781 case NCI_OP_CORE_GENERIC_ERROR_NTF:
782 nci_core_generic_error_ntf_packet(ndev, skb);
785 case NCI_OP_CORE_INTF_ERROR_NTF:
786 nci_core_conn_intf_error_ntf_packet(ndev, skb);
789 case NCI_OP_RF_DISCOVER_NTF:
790 nci_rf_discover_ntf_packet(ndev, skb);
793 case NCI_OP_RF_INTF_ACTIVATED_NTF:
794 nci_rf_intf_activated_ntf_packet(ndev, skb);
797 case NCI_OP_RF_DEACTIVATE_NTF:
798 nci_rf_deactivate_ntf_packet(ndev, skb);
801 case NCI_OP_NFCEE_DISCOVER_NTF:
802 nci_nfcee_discover_ntf_packet(ndev, skb);
805 case NCI_OP_RF_NFCEE_ACTION_NTF:
806 nci_nfcee_action_ntf_packet(ndev, skb);
810 pr_err("unknown ntf opcode 0x%x\n", ntf_opcode);
814 nci_core_ntf_packet(ndev, ntf_opcode, skb);