1 // SPDX-License-Identifier: GPL-2.0-only
3 * The NFC Controller Interface is the communication protocol between an
4 * NFC Controller (NFCC) and a Device Host (DH).
6 * Copyright (C) 2014 Marvell International Ltd.
7 * Copyright (C) 2011 Texas Instruments, Inc.
9 * Written by Ilan Elias <ilane@ti.com>
12 * This file is based on hci_event.c, which was written
13 * by Maxim Krasnyansky.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": %s: " fmt, __func__
18 #include <linux/types.h>
19 #include <linux/interrupt.h>
20 #include <linux/bitops.h>
21 #include <linux/skbuff.h>
24 #include <net/nfc/nci.h>
25 #include <net/nfc/nci_core.h>
26 #include <linux/nfc.h>
28 /* Handle NCI Notification packets */
30 static void nci_core_conn_credits_ntf_packet(struct nci_dev *ndev,
33 struct nci_core_conn_credit_ntf *ntf = (void *) skb->data;
34 struct nci_conn_info *conn_info;
37 pr_debug("num_entries %d\n", ntf->num_entries);
39 if (ntf->num_entries > NCI_MAX_NUM_CONN)
40 ntf->num_entries = NCI_MAX_NUM_CONN;
42 /* update the credits */
43 for (i = 0; i < ntf->num_entries; i++) {
44 ntf->conn_entries[i].conn_id =
45 nci_conn_id(&ntf->conn_entries[i].conn_id);
47 pr_debug("entry[%d]: conn_id %d, credits %d\n",
48 i, ntf->conn_entries[i].conn_id,
49 ntf->conn_entries[i].credits);
51 conn_info = nci_get_conn_info_by_conn_id(ndev,
52 ntf->conn_entries[i].conn_id);
56 atomic_add(ntf->conn_entries[i].credits,
57 &conn_info->credits_cnt);
60 /* trigger the next tx */
61 if (!skb_queue_empty(&ndev->tx_q))
62 queue_work(ndev->tx_wq, &ndev->tx_work);
65 static void nci_core_generic_error_ntf_packet(struct nci_dev *ndev,
68 __u8 status = skb->data[0];
70 pr_debug("status 0x%x\n", status);
72 if (atomic_read(&ndev->state) == NCI_W4_HOST_SELECT) {
73 /* Activation failed, so complete the request
74 (the state remains the same) */
75 nci_req_complete(ndev, status);
79 static void nci_core_conn_intf_error_ntf_packet(struct nci_dev *ndev,
82 struct nci_core_intf_error_ntf *ntf = (void *) skb->data;
84 ntf->conn_id = nci_conn_id(&ntf->conn_id);
86 pr_debug("status 0x%x, conn_id %d\n", ntf->status, ntf->conn_id);
88 /* complete the data exchange transaction, if exists */
89 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
90 nci_data_exchange_complete(ndev, NULL, ntf->conn_id, -EIO);
93 static __u8 *nci_extract_rf_params_nfca_passive_poll(struct nci_dev *ndev,
94 struct rf_tech_specific_params_nfca_poll *nfca_poll,
97 nfca_poll->sens_res = __le16_to_cpu(*((__le16 *)data));
100 nfca_poll->nfcid1_len = min_t(__u8, *data++, NFC_NFCID1_MAXSIZE);
102 pr_debug("sens_res 0x%x, nfcid1_len %d\n",
103 nfca_poll->sens_res, nfca_poll->nfcid1_len);
105 memcpy(nfca_poll->nfcid1, data, nfca_poll->nfcid1_len);
106 data += nfca_poll->nfcid1_len;
108 nfca_poll->sel_res_len = *data++;
110 if (nfca_poll->sel_res_len != 0)
111 nfca_poll->sel_res = *data++;
113 pr_debug("sel_res_len %d, sel_res 0x%x\n",
114 nfca_poll->sel_res_len,
120 static __u8 *nci_extract_rf_params_nfcb_passive_poll(struct nci_dev *ndev,
121 struct rf_tech_specific_params_nfcb_poll *nfcb_poll,
124 nfcb_poll->sensb_res_len = min_t(__u8, *data++, NFC_SENSB_RES_MAXSIZE);
126 pr_debug("sensb_res_len %d\n", nfcb_poll->sensb_res_len);
128 memcpy(nfcb_poll->sensb_res, data, nfcb_poll->sensb_res_len);
129 data += nfcb_poll->sensb_res_len;
134 static __u8 *nci_extract_rf_params_nfcf_passive_poll(struct nci_dev *ndev,
135 struct rf_tech_specific_params_nfcf_poll *nfcf_poll,
138 nfcf_poll->bit_rate = *data++;
139 nfcf_poll->sensf_res_len = min_t(__u8, *data++, NFC_SENSF_RES_MAXSIZE);
141 pr_debug("bit_rate %d, sensf_res_len %d\n",
142 nfcf_poll->bit_rate, nfcf_poll->sensf_res_len);
144 memcpy(nfcf_poll->sensf_res, data, nfcf_poll->sensf_res_len);
145 data += nfcf_poll->sensf_res_len;
150 static __u8 *nci_extract_rf_params_nfcv_passive_poll(struct nci_dev *ndev,
151 struct rf_tech_specific_params_nfcv_poll *nfcv_poll,
155 nfcv_poll->dsfid = *data++;
156 memcpy(nfcv_poll->uid, data, NFC_ISO15693_UID_MAXSIZE);
157 data += NFC_ISO15693_UID_MAXSIZE;
161 static __u8 *nci_extract_rf_params_nfcf_passive_listen(struct nci_dev *ndev,
162 struct rf_tech_specific_params_nfcf_listen *nfcf_listen,
165 nfcf_listen->local_nfcid2_len = min_t(__u8, *data++,
167 memcpy(nfcf_listen->local_nfcid2, data, nfcf_listen->local_nfcid2_len);
168 data += nfcf_listen->local_nfcid2_len;
173 static __u32 nci_get_prop_rf_protocol(struct nci_dev *ndev, __u8 rf_protocol)
175 if (ndev->ops->get_rfprotocol)
176 return ndev->ops->get_rfprotocol(ndev, rf_protocol);
180 static int nci_add_new_protocol(struct nci_dev *ndev,
181 struct nfc_target *target,
183 __u8 rf_tech_and_mode,
186 struct rf_tech_specific_params_nfca_poll *nfca_poll;
187 struct rf_tech_specific_params_nfcb_poll *nfcb_poll;
188 struct rf_tech_specific_params_nfcf_poll *nfcf_poll;
189 struct rf_tech_specific_params_nfcv_poll *nfcv_poll;
192 if (rf_protocol == NCI_RF_PROTOCOL_T1T)
193 protocol = NFC_PROTO_JEWEL_MASK;
194 else if (rf_protocol == NCI_RF_PROTOCOL_T2T)
195 protocol = NFC_PROTO_MIFARE_MASK;
196 else if (rf_protocol == NCI_RF_PROTOCOL_ISO_DEP)
197 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE)
198 protocol = NFC_PROTO_ISO14443_MASK;
200 protocol = NFC_PROTO_ISO14443_B_MASK;
201 else if (rf_protocol == NCI_RF_PROTOCOL_T3T)
202 protocol = NFC_PROTO_FELICA_MASK;
203 else if (rf_protocol == NCI_RF_PROTOCOL_NFC_DEP)
204 protocol = NFC_PROTO_NFC_DEP_MASK;
205 else if (rf_protocol == NCI_RF_PROTOCOL_T5T)
206 protocol = NFC_PROTO_ISO15693_MASK;
208 protocol = nci_get_prop_rf_protocol(ndev, rf_protocol);
210 if (!(protocol & ndev->poll_prots)) {
211 pr_err("the target found does not have the desired protocol\n");
215 if (rf_tech_and_mode == NCI_NFC_A_PASSIVE_POLL_MODE) {
216 nfca_poll = (struct rf_tech_specific_params_nfca_poll *)params;
218 target->sens_res = nfca_poll->sens_res;
219 target->sel_res = nfca_poll->sel_res;
220 target->nfcid1_len = nfca_poll->nfcid1_len;
221 if (target->nfcid1_len > ARRAY_SIZE(target->nfcid1))
223 if (target->nfcid1_len > 0) {
224 memcpy(target->nfcid1, nfca_poll->nfcid1,
227 } else if (rf_tech_and_mode == NCI_NFC_B_PASSIVE_POLL_MODE) {
228 nfcb_poll = (struct rf_tech_specific_params_nfcb_poll *)params;
230 target->sensb_res_len = nfcb_poll->sensb_res_len;
231 if (target->sensb_res_len > ARRAY_SIZE(target->sensb_res))
233 if (target->sensb_res_len > 0) {
234 memcpy(target->sensb_res, nfcb_poll->sensb_res,
235 target->sensb_res_len);
237 } else if (rf_tech_and_mode == NCI_NFC_F_PASSIVE_POLL_MODE) {
238 nfcf_poll = (struct rf_tech_specific_params_nfcf_poll *)params;
240 target->sensf_res_len = nfcf_poll->sensf_res_len;
241 if (target->sensf_res_len > ARRAY_SIZE(target->sensf_res))
243 if (target->sensf_res_len > 0) {
244 memcpy(target->sensf_res, nfcf_poll->sensf_res,
245 target->sensf_res_len);
247 } else if (rf_tech_and_mode == NCI_NFC_V_PASSIVE_POLL_MODE) {
248 nfcv_poll = (struct rf_tech_specific_params_nfcv_poll *)params;
250 target->is_iso15693 = 1;
251 target->iso15693_dsfid = nfcv_poll->dsfid;
252 memcpy(target->iso15693_uid, nfcv_poll->uid, NFC_ISO15693_UID_MAXSIZE);
254 pr_err("unsupported rf_tech_and_mode 0x%x\n", rf_tech_and_mode);
258 target->supported_protocols |= protocol;
260 pr_debug("protocol 0x%x\n", protocol);
265 static void nci_add_new_target(struct nci_dev *ndev,
266 struct nci_rf_discover_ntf *ntf)
268 struct nfc_target *target;
271 for (i = 0; i < ndev->n_targets; i++) {
272 target = &ndev->targets[i];
273 if (target->logical_idx == ntf->rf_discovery_id) {
274 /* This target already exists, add the new protocol */
275 nci_add_new_protocol(ndev, target, ntf->rf_protocol,
276 ntf->rf_tech_and_mode,
277 &ntf->rf_tech_specific_params);
282 /* This is a new target, check if we've enough room */
283 if (ndev->n_targets == NCI_MAX_DISCOVERED_TARGETS) {
284 pr_debug("not enough room, ignoring new target...\n");
288 target = &ndev->targets[ndev->n_targets];
290 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
291 ntf->rf_tech_and_mode,
292 &ntf->rf_tech_specific_params);
294 target->logical_idx = ntf->rf_discovery_id;
297 pr_debug("logical idx %d, n_targets %d\n", target->logical_idx,
302 void nci_clear_target_list(struct nci_dev *ndev)
304 memset(ndev->targets, 0,
305 (sizeof(struct nfc_target)*NCI_MAX_DISCOVERED_TARGETS));
310 static void nci_rf_discover_ntf_packet(struct nci_dev *ndev,
313 struct nci_rf_discover_ntf ntf;
314 __u8 *data = skb->data;
315 bool add_target = true;
317 ntf.rf_discovery_id = *data++;
318 ntf.rf_protocol = *data++;
319 ntf.rf_tech_and_mode = *data++;
320 ntf.rf_tech_specific_params_len = *data++;
322 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
323 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
324 pr_debug("rf_tech_and_mode 0x%x\n", ntf.rf_tech_and_mode);
325 pr_debug("rf_tech_specific_params_len %d\n",
326 ntf.rf_tech_specific_params_len);
328 if (ntf.rf_tech_specific_params_len > 0) {
329 switch (ntf.rf_tech_and_mode) {
330 case NCI_NFC_A_PASSIVE_POLL_MODE:
331 data = nci_extract_rf_params_nfca_passive_poll(ndev,
332 &(ntf.rf_tech_specific_params.nfca_poll), data);
335 case NCI_NFC_B_PASSIVE_POLL_MODE:
336 data = nci_extract_rf_params_nfcb_passive_poll(ndev,
337 &(ntf.rf_tech_specific_params.nfcb_poll), data);
340 case NCI_NFC_F_PASSIVE_POLL_MODE:
341 data = nci_extract_rf_params_nfcf_passive_poll(ndev,
342 &(ntf.rf_tech_specific_params.nfcf_poll), data);
345 case NCI_NFC_V_PASSIVE_POLL_MODE:
346 data = nci_extract_rf_params_nfcv_passive_poll(ndev,
347 &(ntf.rf_tech_specific_params.nfcv_poll), data);
351 pr_err("unsupported rf_tech_and_mode 0x%x\n",
352 ntf.rf_tech_and_mode);
353 data += ntf.rf_tech_specific_params_len;
358 ntf.ntf_type = *data++;
359 pr_debug("ntf_type %d\n", ntf.ntf_type);
361 if (add_target == true)
362 nci_add_new_target(ndev, &ntf);
364 if (ntf.ntf_type == NCI_DISCOVER_NTF_TYPE_MORE) {
365 atomic_set(&ndev->state, NCI_W4_ALL_DISCOVERIES);
367 atomic_set(&ndev->state, NCI_W4_HOST_SELECT);
368 nfc_targets_found(ndev->nfc_dev, ndev->targets,
373 static int nci_extract_activation_params_iso_dep(struct nci_dev *ndev,
374 struct nci_rf_intf_activated_ntf *ntf, __u8 *data)
376 struct activation_params_nfca_poll_iso_dep *nfca_poll;
377 struct activation_params_nfcb_poll_iso_dep *nfcb_poll;
379 switch (ntf->activation_rf_tech_and_mode) {
380 case NCI_NFC_A_PASSIVE_POLL_MODE:
381 nfca_poll = &ntf->activation_params.nfca_poll_iso_dep;
382 nfca_poll->rats_res_len = min_t(__u8, *data++, 20);
383 pr_debug("rats_res_len %d\n", nfca_poll->rats_res_len);
384 if (nfca_poll->rats_res_len > 0) {
385 memcpy(nfca_poll->rats_res,
386 data, nfca_poll->rats_res_len);
390 case NCI_NFC_B_PASSIVE_POLL_MODE:
391 nfcb_poll = &ntf->activation_params.nfcb_poll_iso_dep;
392 nfcb_poll->attrib_res_len = min_t(__u8, *data++, 50);
393 pr_debug("attrib_res_len %d\n", nfcb_poll->attrib_res_len);
394 if (nfcb_poll->attrib_res_len > 0) {
395 memcpy(nfcb_poll->attrib_res,
396 data, nfcb_poll->attrib_res_len);
401 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
402 ntf->activation_rf_tech_and_mode);
403 return NCI_STATUS_RF_PROTOCOL_ERROR;
406 return NCI_STATUS_OK;
409 static int nci_extract_activation_params_nfc_dep(struct nci_dev *ndev,
410 struct nci_rf_intf_activated_ntf *ntf, __u8 *data)
412 struct activation_params_poll_nfc_dep *poll;
413 struct activation_params_listen_nfc_dep *listen;
415 switch (ntf->activation_rf_tech_and_mode) {
416 case NCI_NFC_A_PASSIVE_POLL_MODE:
417 case NCI_NFC_F_PASSIVE_POLL_MODE:
418 poll = &ntf->activation_params.poll_nfc_dep;
419 poll->atr_res_len = min_t(__u8, *data++,
420 NFC_ATR_RES_MAXSIZE - 2);
421 pr_debug("atr_res_len %d\n", poll->atr_res_len);
422 if (poll->atr_res_len > 0)
423 memcpy(poll->atr_res, data, poll->atr_res_len);
426 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
427 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
428 listen = &ntf->activation_params.listen_nfc_dep;
429 listen->atr_req_len = min_t(__u8, *data++,
430 NFC_ATR_REQ_MAXSIZE - 2);
431 pr_debug("atr_req_len %d\n", listen->atr_req_len);
432 if (listen->atr_req_len > 0)
433 memcpy(listen->atr_req, data, listen->atr_req_len);
437 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
438 ntf->activation_rf_tech_and_mode);
439 return NCI_STATUS_RF_PROTOCOL_ERROR;
442 return NCI_STATUS_OK;
445 static void nci_target_auto_activated(struct nci_dev *ndev,
446 struct nci_rf_intf_activated_ntf *ntf)
448 struct nfc_target *target;
451 target = &ndev->targets[ndev->n_targets];
453 rc = nci_add_new_protocol(ndev, target, ntf->rf_protocol,
454 ntf->activation_rf_tech_and_mode,
455 &ntf->rf_tech_specific_params);
459 target->logical_idx = ntf->rf_discovery_id;
462 pr_debug("logical idx %d, n_targets %d\n",
463 target->logical_idx, ndev->n_targets);
465 nfc_targets_found(ndev->nfc_dev, ndev->targets, ndev->n_targets);
468 static int nci_store_general_bytes_nfc_dep(struct nci_dev *ndev,
469 struct nci_rf_intf_activated_ntf *ntf)
471 ndev->remote_gb_len = 0;
473 if (ntf->activation_params_len <= 0)
474 return NCI_STATUS_OK;
476 switch (ntf->activation_rf_tech_and_mode) {
477 case NCI_NFC_A_PASSIVE_POLL_MODE:
478 case NCI_NFC_F_PASSIVE_POLL_MODE:
479 ndev->remote_gb_len = min_t(__u8,
480 (ntf->activation_params.poll_nfc_dep.atr_res_len
481 - NFC_ATR_RES_GT_OFFSET),
482 NFC_ATR_RES_GB_MAXSIZE);
483 memcpy(ndev->remote_gb,
484 (ntf->activation_params.poll_nfc_dep.atr_res
485 + NFC_ATR_RES_GT_OFFSET),
486 ndev->remote_gb_len);
489 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
490 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
491 ndev->remote_gb_len = min_t(__u8,
492 (ntf->activation_params.listen_nfc_dep.atr_req_len
493 - NFC_ATR_REQ_GT_OFFSET),
494 NFC_ATR_REQ_GB_MAXSIZE);
495 memcpy(ndev->remote_gb,
496 (ntf->activation_params.listen_nfc_dep.atr_req
497 + NFC_ATR_REQ_GT_OFFSET),
498 ndev->remote_gb_len);
502 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
503 ntf->activation_rf_tech_and_mode);
504 return NCI_STATUS_RF_PROTOCOL_ERROR;
507 return NCI_STATUS_OK;
510 static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
513 struct nci_conn_info *conn_info;
514 struct nci_rf_intf_activated_ntf ntf;
515 __u8 *data = skb->data;
516 int err = NCI_STATUS_OK;
518 ntf.rf_discovery_id = *data++;
519 ntf.rf_interface = *data++;
520 ntf.rf_protocol = *data++;
521 ntf.activation_rf_tech_and_mode = *data++;
522 ntf.max_data_pkt_payload_size = *data++;
523 ntf.initial_num_credits = *data++;
524 ntf.rf_tech_specific_params_len = *data++;
526 pr_debug("rf_discovery_id %d\n", ntf.rf_discovery_id);
527 pr_debug("rf_interface 0x%x\n", ntf.rf_interface);
528 pr_debug("rf_protocol 0x%x\n", ntf.rf_protocol);
529 pr_debug("activation_rf_tech_and_mode 0x%x\n",
530 ntf.activation_rf_tech_and_mode);
531 pr_debug("max_data_pkt_payload_size 0x%x\n",
532 ntf.max_data_pkt_payload_size);
533 pr_debug("initial_num_credits 0x%x\n",
534 ntf.initial_num_credits);
535 pr_debug("rf_tech_specific_params_len %d\n",
536 ntf.rf_tech_specific_params_len);
538 /* If this contains a value of 0x00 (NFCEE Direct RF
539 * Interface) then all following parameters SHALL contain a
540 * value of 0 and SHALL be ignored.
542 if (ntf.rf_interface == NCI_RF_INTERFACE_NFCEE_DIRECT)
545 if (ntf.rf_tech_specific_params_len > 0) {
546 switch (ntf.activation_rf_tech_and_mode) {
547 case NCI_NFC_A_PASSIVE_POLL_MODE:
548 data = nci_extract_rf_params_nfca_passive_poll(ndev,
549 &(ntf.rf_tech_specific_params.nfca_poll), data);
552 case NCI_NFC_B_PASSIVE_POLL_MODE:
553 data = nci_extract_rf_params_nfcb_passive_poll(ndev,
554 &(ntf.rf_tech_specific_params.nfcb_poll), data);
557 case NCI_NFC_F_PASSIVE_POLL_MODE:
558 data = nci_extract_rf_params_nfcf_passive_poll(ndev,
559 &(ntf.rf_tech_specific_params.nfcf_poll), data);
562 case NCI_NFC_V_PASSIVE_POLL_MODE:
563 data = nci_extract_rf_params_nfcv_passive_poll(ndev,
564 &(ntf.rf_tech_specific_params.nfcv_poll), data);
567 case NCI_NFC_A_PASSIVE_LISTEN_MODE:
568 /* no RF technology specific parameters */
571 case NCI_NFC_F_PASSIVE_LISTEN_MODE:
572 data = nci_extract_rf_params_nfcf_passive_listen(ndev,
573 &(ntf.rf_tech_specific_params.nfcf_listen),
578 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
579 ntf.activation_rf_tech_and_mode);
580 err = NCI_STATUS_RF_PROTOCOL_ERROR;
585 ntf.data_exch_rf_tech_and_mode = *data++;
586 ntf.data_exch_tx_bit_rate = *data++;
587 ntf.data_exch_rx_bit_rate = *data++;
588 ntf.activation_params_len = *data++;
590 pr_debug("data_exch_rf_tech_and_mode 0x%x\n",
591 ntf.data_exch_rf_tech_and_mode);
592 pr_debug("data_exch_tx_bit_rate 0x%x\n", ntf.data_exch_tx_bit_rate);
593 pr_debug("data_exch_rx_bit_rate 0x%x\n", ntf.data_exch_rx_bit_rate);
594 pr_debug("activation_params_len %d\n", ntf.activation_params_len);
596 if (ntf.activation_params_len > 0) {
597 switch (ntf.rf_interface) {
598 case NCI_RF_INTERFACE_ISO_DEP:
599 err = nci_extract_activation_params_iso_dep(ndev,
603 case NCI_RF_INTERFACE_NFC_DEP:
604 err = nci_extract_activation_params_nfc_dep(ndev,
608 case NCI_RF_INTERFACE_FRAME:
609 /* no activation params */
613 pr_err("unsupported rf_interface 0x%x\n",
615 err = NCI_STATUS_RF_PROTOCOL_ERROR;
621 if (err == NCI_STATUS_OK) {
622 conn_info = ndev->rf_conn_info;
626 conn_info->max_pkt_payload_len = ntf.max_data_pkt_payload_size;
627 conn_info->initial_num_credits = ntf.initial_num_credits;
629 /* set the available credits to initial value */
630 atomic_set(&conn_info->credits_cnt,
631 conn_info->initial_num_credits);
633 /* store general bytes to be reported later in dep_link_up */
634 if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) {
635 err = nci_store_general_bytes_nfc_dep(ndev, &ntf);
636 if (err != NCI_STATUS_OK)
637 pr_err("unable to store general bytes\n");
641 if (!(ntf.activation_rf_tech_and_mode & NCI_RF_TECH_MODE_LISTEN_MASK)) {
643 if (atomic_read(&ndev->state) == NCI_DISCOVERY) {
644 /* A single target was found and activated
646 atomic_set(&ndev->state, NCI_POLL_ACTIVE);
647 if (err == NCI_STATUS_OK)
648 nci_target_auto_activated(ndev, &ntf);
649 } else { /* ndev->state == NCI_W4_HOST_SELECT */
650 /* A selected target was activated, so complete the
652 atomic_set(&ndev->state, NCI_POLL_ACTIVE);
653 nci_req_complete(ndev, err);
658 atomic_set(&ndev->state, NCI_LISTEN_ACTIVE);
659 if (err == NCI_STATUS_OK &&
660 ntf.rf_protocol == NCI_RF_PROTOCOL_NFC_DEP) {
661 err = nfc_tm_activated(ndev->nfc_dev,
662 NFC_PROTO_NFC_DEP_MASK,
665 ndev->remote_gb_len);
666 if (err != NCI_STATUS_OK)
667 pr_err("error when signaling tm activation\n");
672 static void nci_rf_deactivate_ntf_packet(struct nci_dev *ndev,
675 struct nci_conn_info *conn_info;
676 struct nci_rf_deactivate_ntf *ntf = (void *) skb->data;
678 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf->type, ntf->reason);
680 conn_info = ndev->rf_conn_info;
684 /* drop tx data queue */
685 skb_queue_purge(&ndev->tx_q);
687 /* drop partial rx data packet */
688 if (ndev->rx_data_reassembly) {
689 kfree_skb(ndev->rx_data_reassembly);
690 ndev->rx_data_reassembly = NULL;
693 /* complete the data exchange transaction, if exists */
694 if (test_bit(NCI_DATA_EXCHANGE, &ndev->flags))
695 nci_data_exchange_complete(ndev, NULL, NCI_STATIC_RF_CONN_ID,
699 case NCI_DEACTIVATE_TYPE_IDLE_MODE:
700 nci_clear_target_list(ndev);
701 atomic_set(&ndev->state, NCI_IDLE);
703 case NCI_DEACTIVATE_TYPE_SLEEP_MODE:
704 case NCI_DEACTIVATE_TYPE_SLEEP_AF_MODE:
705 atomic_set(&ndev->state, NCI_W4_HOST_SELECT);
707 case NCI_DEACTIVATE_TYPE_DISCOVERY:
708 nci_clear_target_list(ndev);
709 atomic_set(&ndev->state, NCI_DISCOVERY);
713 nci_req_complete(ndev, NCI_STATUS_OK);
716 static void nci_nfcee_discover_ntf_packet(struct nci_dev *ndev,
719 u8 status = NCI_STATUS_OK;
720 struct nci_nfcee_discover_ntf *nfcee_ntf =
721 (struct nci_nfcee_discover_ntf *)skb->data;
725 /* NFCForum NCI 9.2.1 HCI Network Specific Handling
726 * If the NFCC supports the HCI Network, it SHALL return one,
727 * and only one, NFCEE_DISCOVER_NTF with a Protocol type of
728 * “HCI Access”, even if the HCI Network contains multiple NFCEEs.
730 ndev->hci_dev->nfcee_id = nfcee_ntf->nfcee_id;
731 ndev->cur_params.id = nfcee_ntf->nfcee_id;
733 nci_req_complete(ndev, status);
736 static void nci_nfcee_action_ntf_packet(struct nci_dev *ndev,
742 void nci_ntf_packet(struct nci_dev *ndev, struct sk_buff *skb)
744 __u16 ntf_opcode = nci_opcode(skb->data);
746 pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
748 nci_opcode_gid(ntf_opcode),
749 nci_opcode_oid(ntf_opcode),
750 nci_plen(skb->data));
752 /* strip the nci control header */
753 skb_pull(skb, NCI_CTRL_HDR_SIZE);
755 if (nci_opcode_gid(ntf_opcode) == NCI_GID_PROPRIETARY) {
756 if (nci_prop_ntf_packet(ndev, ntf_opcode, skb) == -ENOTSUPP) {
757 pr_err("unsupported ntf opcode 0x%x\n",
764 switch (ntf_opcode) {
765 case NCI_OP_CORE_CONN_CREDITS_NTF:
766 nci_core_conn_credits_ntf_packet(ndev, skb);
769 case NCI_OP_CORE_GENERIC_ERROR_NTF:
770 nci_core_generic_error_ntf_packet(ndev, skb);
773 case NCI_OP_CORE_INTF_ERROR_NTF:
774 nci_core_conn_intf_error_ntf_packet(ndev, skb);
777 case NCI_OP_RF_DISCOVER_NTF:
778 nci_rf_discover_ntf_packet(ndev, skb);
781 case NCI_OP_RF_INTF_ACTIVATED_NTF:
782 nci_rf_intf_activated_ntf_packet(ndev, skb);
785 case NCI_OP_RF_DEACTIVATE_NTF:
786 nci_rf_deactivate_ntf_packet(ndev, skb);
789 case NCI_OP_NFCEE_DISCOVER_NTF:
790 nci_nfcee_discover_ntf_packet(ndev, skb);
793 case NCI_OP_RF_NFCEE_ACTION_NTF:
794 nci_nfcee_action_ntf_packet(ndev, skb);
798 pr_err("unknown ntf opcode 0x%x\n", ntf_opcode);
802 nci_core_ntf_packet(ndev, ntf_opcode, skb);