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_reset_ntf_packet(struct nci_dev
*ndev
,
33 /* Handle NCI 2.x core reset notification */
34 struct nci_core_reset_ntf
*ntf
= (void *)skb
->data
;
36 ndev
->nci_ver
= ntf
->nci_ver
;
37 pr_debug("nci_ver 0x%x, config_status 0x%x\n",
38 ntf
->nci_ver
, ntf
->config_status
);
40 ndev
->manufact_id
= ntf
->manufact_id
;
41 ndev
->manufact_specific_info
=
42 __le32_to_cpu(ntf
->manufact_specific_info
);
44 nci_req_complete(ndev
, NCI_STATUS_OK
);
47 static void nci_core_conn_credits_ntf_packet(struct nci_dev
*ndev
,
50 struct nci_core_conn_credit_ntf
*ntf
= (void *) skb
->data
;
51 struct nci_conn_info
*conn_info
;
54 pr_debug("num_entries %d\n", ntf
->num_entries
);
56 if (ntf
->num_entries
> NCI_MAX_NUM_CONN
)
57 ntf
->num_entries
= NCI_MAX_NUM_CONN
;
59 /* update the credits */
60 for (i
= 0; i
< ntf
->num_entries
; i
++) {
61 ntf
->conn_entries
[i
].conn_id
=
62 nci_conn_id(&ntf
->conn_entries
[i
].conn_id
);
64 pr_debug("entry[%d]: conn_id %d, credits %d\n",
65 i
, ntf
->conn_entries
[i
].conn_id
,
66 ntf
->conn_entries
[i
].credits
);
68 conn_info
= nci_get_conn_info_by_conn_id(ndev
,
69 ntf
->conn_entries
[i
].conn_id
);
73 atomic_add(ntf
->conn_entries
[i
].credits
,
74 &conn_info
->credits_cnt
);
77 /* trigger the next tx */
78 if (!skb_queue_empty(&ndev
->tx_q
))
79 queue_work(ndev
->tx_wq
, &ndev
->tx_work
);
82 static void nci_core_generic_error_ntf_packet(struct nci_dev
*ndev
,
85 __u8 status
= skb
->data
[0];
87 pr_debug("status 0x%x\n", status
);
89 if (atomic_read(&ndev
->state
) == NCI_W4_HOST_SELECT
) {
90 /* Activation failed, so complete the request
91 (the state remains the same) */
92 nci_req_complete(ndev
, status
);
96 static void nci_core_conn_intf_error_ntf_packet(struct nci_dev
*ndev
,
99 struct nci_core_intf_error_ntf
*ntf
= (void *) skb
->data
;
101 ntf
->conn_id
= nci_conn_id(&ntf
->conn_id
);
103 pr_debug("status 0x%x, conn_id %d\n", ntf
->status
, ntf
->conn_id
);
105 /* complete the data exchange transaction, if exists */
106 if (test_bit(NCI_DATA_EXCHANGE
, &ndev
->flags
))
107 nci_data_exchange_complete(ndev
, NULL
, ntf
->conn_id
, -EIO
);
110 static __u8
*nci_extract_rf_params_nfca_passive_poll(struct nci_dev
*ndev
,
111 struct rf_tech_specific_params_nfca_poll
*nfca_poll
,
114 nfca_poll
->sens_res
= __le16_to_cpu(*((__le16
*)data
));
117 nfca_poll
->nfcid1_len
= min_t(__u8
, *data
++, NFC_NFCID1_MAXSIZE
);
119 pr_debug("sens_res 0x%x, nfcid1_len %d\n",
120 nfca_poll
->sens_res
, nfca_poll
->nfcid1_len
);
122 memcpy(nfca_poll
->nfcid1
, data
, nfca_poll
->nfcid1_len
);
123 data
+= nfca_poll
->nfcid1_len
;
125 nfca_poll
->sel_res_len
= *data
++;
127 if (nfca_poll
->sel_res_len
!= 0)
128 nfca_poll
->sel_res
= *data
++;
130 pr_debug("sel_res_len %d, sel_res 0x%x\n",
131 nfca_poll
->sel_res_len
,
137 static __u8
*nci_extract_rf_params_nfcb_passive_poll(struct nci_dev
*ndev
,
138 struct rf_tech_specific_params_nfcb_poll
*nfcb_poll
,
141 nfcb_poll
->sensb_res_len
= min_t(__u8
, *data
++, NFC_SENSB_RES_MAXSIZE
);
143 pr_debug("sensb_res_len %d\n", nfcb_poll
->sensb_res_len
);
145 memcpy(nfcb_poll
->sensb_res
, data
, nfcb_poll
->sensb_res_len
);
146 data
+= nfcb_poll
->sensb_res_len
;
151 static __u8
*nci_extract_rf_params_nfcf_passive_poll(struct nci_dev
*ndev
,
152 struct rf_tech_specific_params_nfcf_poll
*nfcf_poll
,
155 nfcf_poll
->bit_rate
= *data
++;
156 nfcf_poll
->sensf_res_len
= min_t(__u8
, *data
++, NFC_SENSF_RES_MAXSIZE
);
158 pr_debug("bit_rate %d, sensf_res_len %d\n",
159 nfcf_poll
->bit_rate
, nfcf_poll
->sensf_res_len
);
161 memcpy(nfcf_poll
->sensf_res
, data
, nfcf_poll
->sensf_res_len
);
162 data
+= nfcf_poll
->sensf_res_len
;
167 static __u8
*nci_extract_rf_params_nfcv_passive_poll(struct nci_dev
*ndev
,
168 struct rf_tech_specific_params_nfcv_poll
*nfcv_poll
,
172 nfcv_poll
->dsfid
= *data
++;
173 memcpy(nfcv_poll
->uid
, data
, NFC_ISO15693_UID_MAXSIZE
);
174 data
+= NFC_ISO15693_UID_MAXSIZE
;
178 static __u8
*nci_extract_rf_params_nfcf_passive_listen(struct nci_dev
*ndev
,
179 struct rf_tech_specific_params_nfcf_listen
*nfcf_listen
,
182 nfcf_listen
->local_nfcid2_len
= min_t(__u8
, *data
++,
184 memcpy(nfcf_listen
->local_nfcid2
, data
, nfcf_listen
->local_nfcid2_len
);
185 data
+= nfcf_listen
->local_nfcid2_len
;
190 static __u32
nci_get_prop_rf_protocol(struct nci_dev
*ndev
, __u8 rf_protocol
)
192 if (ndev
->ops
->get_rfprotocol
)
193 return ndev
->ops
->get_rfprotocol(ndev
, rf_protocol
);
197 static int nci_add_new_protocol(struct nci_dev
*ndev
,
198 struct nfc_target
*target
,
200 __u8 rf_tech_and_mode
,
203 struct rf_tech_specific_params_nfca_poll
*nfca_poll
;
204 struct rf_tech_specific_params_nfcb_poll
*nfcb_poll
;
205 struct rf_tech_specific_params_nfcf_poll
*nfcf_poll
;
206 struct rf_tech_specific_params_nfcv_poll
*nfcv_poll
;
209 if (rf_protocol
== NCI_RF_PROTOCOL_T1T
)
210 protocol
= NFC_PROTO_JEWEL_MASK
;
211 else if (rf_protocol
== NCI_RF_PROTOCOL_T2T
)
212 protocol
= NFC_PROTO_MIFARE_MASK
;
213 else if (rf_protocol
== NCI_RF_PROTOCOL_ISO_DEP
)
214 if (rf_tech_and_mode
== NCI_NFC_A_PASSIVE_POLL_MODE
)
215 protocol
= NFC_PROTO_ISO14443_MASK
;
217 protocol
= NFC_PROTO_ISO14443_B_MASK
;
218 else if (rf_protocol
== NCI_RF_PROTOCOL_T3T
)
219 protocol
= NFC_PROTO_FELICA_MASK
;
220 else if (rf_protocol
== NCI_RF_PROTOCOL_NFC_DEP
)
221 protocol
= NFC_PROTO_NFC_DEP_MASK
;
222 else if (rf_protocol
== NCI_RF_PROTOCOL_T5T
)
223 protocol
= NFC_PROTO_ISO15693_MASK
;
225 protocol
= nci_get_prop_rf_protocol(ndev
, rf_protocol
);
227 if (!(protocol
& ndev
->poll_prots
)) {
228 pr_err("the target found does not have the desired protocol\n");
232 if (rf_tech_and_mode
== NCI_NFC_A_PASSIVE_POLL_MODE
) {
233 nfca_poll
= (struct rf_tech_specific_params_nfca_poll
*)params
;
235 target
->sens_res
= nfca_poll
->sens_res
;
236 target
->sel_res
= nfca_poll
->sel_res
;
237 target
->nfcid1_len
= nfca_poll
->nfcid1_len
;
238 if (target
->nfcid1_len
> 0) {
239 memcpy(target
->nfcid1
, nfca_poll
->nfcid1
,
242 } else if (rf_tech_and_mode
== NCI_NFC_B_PASSIVE_POLL_MODE
) {
243 nfcb_poll
= (struct rf_tech_specific_params_nfcb_poll
*)params
;
245 target
->sensb_res_len
= nfcb_poll
->sensb_res_len
;
246 if (target
->sensb_res_len
> 0) {
247 memcpy(target
->sensb_res
, nfcb_poll
->sensb_res
,
248 target
->sensb_res_len
);
250 } else if (rf_tech_and_mode
== NCI_NFC_F_PASSIVE_POLL_MODE
) {
251 nfcf_poll
= (struct rf_tech_specific_params_nfcf_poll
*)params
;
253 target
->sensf_res_len
= nfcf_poll
->sensf_res_len
;
254 if (target
->sensf_res_len
> 0) {
255 memcpy(target
->sensf_res
, nfcf_poll
->sensf_res
,
256 target
->sensf_res_len
);
258 } else if (rf_tech_and_mode
== NCI_NFC_V_PASSIVE_POLL_MODE
) {
259 nfcv_poll
= (struct rf_tech_specific_params_nfcv_poll
*)params
;
261 target
->is_iso15693
= 1;
262 target
->iso15693_dsfid
= nfcv_poll
->dsfid
;
263 memcpy(target
->iso15693_uid
, nfcv_poll
->uid
, NFC_ISO15693_UID_MAXSIZE
);
265 pr_err("unsupported rf_tech_and_mode 0x%x\n", rf_tech_and_mode
);
269 target
->supported_protocols
|= protocol
;
271 pr_debug("protocol 0x%x\n", protocol
);
276 static void nci_add_new_target(struct nci_dev
*ndev
,
277 struct nci_rf_discover_ntf
*ntf
)
279 struct nfc_target
*target
;
282 for (i
= 0; i
< ndev
->n_targets
; i
++) {
283 target
= &ndev
->targets
[i
];
284 if (target
->logical_idx
== ntf
->rf_discovery_id
) {
285 /* This target already exists, add the new protocol */
286 nci_add_new_protocol(ndev
, target
, ntf
->rf_protocol
,
287 ntf
->rf_tech_and_mode
,
288 &ntf
->rf_tech_specific_params
);
293 /* This is a new target, check if we've enough room */
294 if (ndev
->n_targets
== NCI_MAX_DISCOVERED_TARGETS
) {
295 pr_debug("not enough room, ignoring new target...\n");
299 target
= &ndev
->targets
[ndev
->n_targets
];
301 rc
= nci_add_new_protocol(ndev
, target
, ntf
->rf_protocol
,
302 ntf
->rf_tech_and_mode
,
303 &ntf
->rf_tech_specific_params
);
305 target
->logical_idx
= ntf
->rf_discovery_id
;
308 pr_debug("logical idx %d, n_targets %d\n", target
->logical_idx
,
313 void nci_clear_target_list(struct nci_dev
*ndev
)
315 memset(ndev
->targets
, 0,
316 (sizeof(struct nfc_target
)*NCI_MAX_DISCOVERED_TARGETS
));
321 static void nci_rf_discover_ntf_packet(struct nci_dev
*ndev
,
324 struct nci_rf_discover_ntf ntf
;
325 __u8
*data
= skb
->data
;
326 bool add_target
= true;
328 ntf
.rf_discovery_id
= *data
++;
329 ntf
.rf_protocol
= *data
++;
330 ntf
.rf_tech_and_mode
= *data
++;
331 ntf
.rf_tech_specific_params_len
= *data
++;
333 pr_debug("rf_discovery_id %d\n", ntf
.rf_discovery_id
);
334 pr_debug("rf_protocol 0x%x\n", ntf
.rf_protocol
);
335 pr_debug("rf_tech_and_mode 0x%x\n", ntf
.rf_tech_and_mode
);
336 pr_debug("rf_tech_specific_params_len %d\n",
337 ntf
.rf_tech_specific_params_len
);
339 if (ntf
.rf_tech_specific_params_len
> 0) {
340 switch (ntf
.rf_tech_and_mode
) {
341 case NCI_NFC_A_PASSIVE_POLL_MODE
:
342 data
= nci_extract_rf_params_nfca_passive_poll(ndev
,
343 &(ntf
.rf_tech_specific_params
.nfca_poll
), data
);
346 case NCI_NFC_B_PASSIVE_POLL_MODE
:
347 data
= nci_extract_rf_params_nfcb_passive_poll(ndev
,
348 &(ntf
.rf_tech_specific_params
.nfcb_poll
), data
);
351 case NCI_NFC_F_PASSIVE_POLL_MODE
:
352 data
= nci_extract_rf_params_nfcf_passive_poll(ndev
,
353 &(ntf
.rf_tech_specific_params
.nfcf_poll
), data
);
356 case NCI_NFC_V_PASSIVE_POLL_MODE
:
357 data
= nci_extract_rf_params_nfcv_passive_poll(ndev
,
358 &(ntf
.rf_tech_specific_params
.nfcv_poll
), data
);
362 pr_err("unsupported rf_tech_and_mode 0x%x\n",
363 ntf
.rf_tech_and_mode
);
364 data
+= ntf
.rf_tech_specific_params_len
;
369 ntf
.ntf_type
= *data
++;
370 pr_debug("ntf_type %d\n", ntf
.ntf_type
);
372 if (add_target
== true)
373 nci_add_new_target(ndev
, &ntf
);
375 if (ntf
.ntf_type
== NCI_DISCOVER_NTF_TYPE_MORE
) {
376 atomic_set(&ndev
->state
, NCI_W4_ALL_DISCOVERIES
);
378 atomic_set(&ndev
->state
, NCI_W4_HOST_SELECT
);
379 nfc_targets_found(ndev
->nfc_dev
, ndev
->targets
,
384 static int nci_extract_activation_params_iso_dep(struct nci_dev
*ndev
,
385 struct nci_rf_intf_activated_ntf
*ntf
, __u8
*data
)
387 struct activation_params_nfca_poll_iso_dep
*nfca_poll
;
388 struct activation_params_nfcb_poll_iso_dep
*nfcb_poll
;
390 switch (ntf
->activation_rf_tech_and_mode
) {
391 case NCI_NFC_A_PASSIVE_POLL_MODE
:
392 nfca_poll
= &ntf
->activation_params
.nfca_poll_iso_dep
;
393 nfca_poll
->rats_res_len
= min_t(__u8
, *data
++, 20);
394 pr_debug("rats_res_len %d\n", nfca_poll
->rats_res_len
);
395 if (nfca_poll
->rats_res_len
> 0) {
396 memcpy(nfca_poll
->rats_res
,
397 data
, nfca_poll
->rats_res_len
);
401 case NCI_NFC_B_PASSIVE_POLL_MODE
:
402 nfcb_poll
= &ntf
->activation_params
.nfcb_poll_iso_dep
;
403 nfcb_poll
->attrib_res_len
= min_t(__u8
, *data
++, 50);
404 pr_debug("attrib_res_len %d\n", nfcb_poll
->attrib_res_len
);
405 if (nfcb_poll
->attrib_res_len
> 0) {
406 memcpy(nfcb_poll
->attrib_res
,
407 data
, nfcb_poll
->attrib_res_len
);
412 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
413 ntf
->activation_rf_tech_and_mode
);
414 return NCI_STATUS_RF_PROTOCOL_ERROR
;
417 return NCI_STATUS_OK
;
420 static int nci_extract_activation_params_nfc_dep(struct nci_dev
*ndev
,
421 struct nci_rf_intf_activated_ntf
*ntf
, __u8
*data
)
423 struct activation_params_poll_nfc_dep
*poll
;
424 struct activation_params_listen_nfc_dep
*listen
;
426 switch (ntf
->activation_rf_tech_and_mode
) {
427 case NCI_NFC_A_PASSIVE_POLL_MODE
:
428 case NCI_NFC_F_PASSIVE_POLL_MODE
:
429 poll
= &ntf
->activation_params
.poll_nfc_dep
;
430 poll
->atr_res_len
= min_t(__u8
, *data
++,
431 NFC_ATR_RES_MAXSIZE
- 2);
432 pr_debug("atr_res_len %d\n", poll
->atr_res_len
);
433 if (poll
->atr_res_len
> 0)
434 memcpy(poll
->atr_res
, data
, poll
->atr_res_len
);
437 case NCI_NFC_A_PASSIVE_LISTEN_MODE
:
438 case NCI_NFC_F_PASSIVE_LISTEN_MODE
:
439 listen
= &ntf
->activation_params
.listen_nfc_dep
;
440 listen
->atr_req_len
= min_t(__u8
, *data
++,
441 NFC_ATR_REQ_MAXSIZE
- 2);
442 pr_debug("atr_req_len %d\n", listen
->atr_req_len
);
443 if (listen
->atr_req_len
> 0)
444 memcpy(listen
->atr_req
, data
, listen
->atr_req_len
);
448 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
449 ntf
->activation_rf_tech_and_mode
);
450 return NCI_STATUS_RF_PROTOCOL_ERROR
;
453 return NCI_STATUS_OK
;
456 static void nci_target_auto_activated(struct nci_dev
*ndev
,
457 struct nci_rf_intf_activated_ntf
*ntf
)
459 struct nfc_target
*target
;
462 target
= &ndev
->targets
[ndev
->n_targets
];
464 rc
= nci_add_new_protocol(ndev
, target
, ntf
->rf_protocol
,
465 ntf
->activation_rf_tech_and_mode
,
466 &ntf
->rf_tech_specific_params
);
470 target
->logical_idx
= ntf
->rf_discovery_id
;
473 pr_debug("logical idx %d, n_targets %d\n",
474 target
->logical_idx
, ndev
->n_targets
);
476 nfc_targets_found(ndev
->nfc_dev
, ndev
->targets
, ndev
->n_targets
);
479 static int nci_store_general_bytes_nfc_dep(struct nci_dev
*ndev
,
480 struct nci_rf_intf_activated_ntf
*ntf
)
482 ndev
->remote_gb_len
= 0;
484 if (ntf
->activation_params_len
<= 0)
485 return NCI_STATUS_OK
;
487 switch (ntf
->activation_rf_tech_and_mode
) {
488 case NCI_NFC_A_PASSIVE_POLL_MODE
:
489 case NCI_NFC_F_PASSIVE_POLL_MODE
:
490 ndev
->remote_gb_len
= min_t(__u8
,
491 (ntf
->activation_params
.poll_nfc_dep
.atr_res_len
492 - NFC_ATR_RES_GT_OFFSET
),
493 NFC_ATR_RES_GB_MAXSIZE
);
494 memcpy(ndev
->remote_gb
,
495 (ntf
->activation_params
.poll_nfc_dep
.atr_res
496 + NFC_ATR_RES_GT_OFFSET
),
497 ndev
->remote_gb_len
);
500 case NCI_NFC_A_PASSIVE_LISTEN_MODE
:
501 case NCI_NFC_F_PASSIVE_LISTEN_MODE
:
502 ndev
->remote_gb_len
= min_t(__u8
,
503 (ntf
->activation_params
.listen_nfc_dep
.atr_req_len
504 - NFC_ATR_REQ_GT_OFFSET
),
505 NFC_ATR_REQ_GB_MAXSIZE
);
506 memcpy(ndev
->remote_gb
,
507 (ntf
->activation_params
.listen_nfc_dep
.atr_req
508 + NFC_ATR_REQ_GT_OFFSET
),
509 ndev
->remote_gb_len
);
513 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
514 ntf
->activation_rf_tech_and_mode
);
515 return NCI_STATUS_RF_PROTOCOL_ERROR
;
518 return NCI_STATUS_OK
;
521 static void nci_rf_intf_activated_ntf_packet(struct nci_dev
*ndev
,
524 struct nci_conn_info
*conn_info
;
525 struct nci_rf_intf_activated_ntf ntf
;
526 __u8
*data
= skb
->data
;
527 int err
= NCI_STATUS_OK
;
529 ntf
.rf_discovery_id
= *data
++;
530 ntf
.rf_interface
= *data
++;
531 ntf
.rf_protocol
= *data
++;
532 ntf
.activation_rf_tech_and_mode
= *data
++;
533 ntf
.max_data_pkt_payload_size
= *data
++;
534 ntf
.initial_num_credits
= *data
++;
535 ntf
.rf_tech_specific_params_len
= *data
++;
537 pr_debug("rf_discovery_id %d\n", ntf
.rf_discovery_id
);
538 pr_debug("rf_interface 0x%x\n", ntf
.rf_interface
);
539 pr_debug("rf_protocol 0x%x\n", ntf
.rf_protocol
);
540 pr_debug("activation_rf_tech_and_mode 0x%x\n",
541 ntf
.activation_rf_tech_and_mode
);
542 pr_debug("max_data_pkt_payload_size 0x%x\n",
543 ntf
.max_data_pkt_payload_size
);
544 pr_debug("initial_num_credits 0x%x\n",
545 ntf
.initial_num_credits
);
546 pr_debug("rf_tech_specific_params_len %d\n",
547 ntf
.rf_tech_specific_params_len
);
549 /* If this contains a value of 0x00 (NFCEE Direct RF
550 * Interface) then all following parameters SHALL contain a
551 * value of 0 and SHALL be ignored.
553 if (ntf
.rf_interface
== NCI_RF_INTERFACE_NFCEE_DIRECT
)
556 if (ntf
.rf_tech_specific_params_len
> 0) {
557 switch (ntf
.activation_rf_tech_and_mode
) {
558 case NCI_NFC_A_PASSIVE_POLL_MODE
:
559 data
= nci_extract_rf_params_nfca_passive_poll(ndev
,
560 &(ntf
.rf_tech_specific_params
.nfca_poll
), data
);
563 case NCI_NFC_B_PASSIVE_POLL_MODE
:
564 data
= nci_extract_rf_params_nfcb_passive_poll(ndev
,
565 &(ntf
.rf_tech_specific_params
.nfcb_poll
), data
);
568 case NCI_NFC_F_PASSIVE_POLL_MODE
:
569 data
= nci_extract_rf_params_nfcf_passive_poll(ndev
,
570 &(ntf
.rf_tech_specific_params
.nfcf_poll
), data
);
573 case NCI_NFC_V_PASSIVE_POLL_MODE
:
574 data
= nci_extract_rf_params_nfcv_passive_poll(ndev
,
575 &(ntf
.rf_tech_specific_params
.nfcv_poll
), data
);
578 case NCI_NFC_A_PASSIVE_LISTEN_MODE
:
579 /* no RF technology specific parameters */
582 case NCI_NFC_F_PASSIVE_LISTEN_MODE
:
583 data
= nci_extract_rf_params_nfcf_passive_listen(ndev
,
584 &(ntf
.rf_tech_specific_params
.nfcf_listen
),
589 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
590 ntf
.activation_rf_tech_and_mode
);
591 err
= NCI_STATUS_RF_PROTOCOL_ERROR
;
596 ntf
.data_exch_rf_tech_and_mode
= *data
++;
597 ntf
.data_exch_tx_bit_rate
= *data
++;
598 ntf
.data_exch_rx_bit_rate
= *data
++;
599 ntf
.activation_params_len
= *data
++;
601 pr_debug("data_exch_rf_tech_and_mode 0x%x\n",
602 ntf
.data_exch_rf_tech_and_mode
);
603 pr_debug("data_exch_tx_bit_rate 0x%x\n", ntf
.data_exch_tx_bit_rate
);
604 pr_debug("data_exch_rx_bit_rate 0x%x\n", ntf
.data_exch_rx_bit_rate
);
605 pr_debug("activation_params_len %d\n", ntf
.activation_params_len
);
607 if (ntf
.activation_params_len
> 0) {
608 switch (ntf
.rf_interface
) {
609 case NCI_RF_INTERFACE_ISO_DEP
:
610 err
= nci_extract_activation_params_iso_dep(ndev
,
614 case NCI_RF_INTERFACE_NFC_DEP
:
615 err
= nci_extract_activation_params_nfc_dep(ndev
,
619 case NCI_RF_INTERFACE_FRAME
:
620 /* no activation params */
624 pr_err("unsupported rf_interface 0x%x\n",
626 err
= NCI_STATUS_RF_PROTOCOL_ERROR
;
632 if (err
== NCI_STATUS_OK
) {
633 conn_info
= ndev
->rf_conn_info
;
637 conn_info
->max_pkt_payload_len
= ntf
.max_data_pkt_payload_size
;
638 conn_info
->initial_num_credits
= ntf
.initial_num_credits
;
640 /* set the available credits to initial value */
641 atomic_set(&conn_info
->credits_cnt
,
642 conn_info
->initial_num_credits
);
644 /* store general bytes to be reported later in dep_link_up */
645 if (ntf
.rf_interface
== NCI_RF_INTERFACE_NFC_DEP
) {
646 err
= nci_store_general_bytes_nfc_dep(ndev
, &ntf
);
647 if (err
!= NCI_STATUS_OK
)
648 pr_err("unable to store general bytes\n");
652 if (!(ntf
.activation_rf_tech_and_mode
& NCI_RF_TECH_MODE_LISTEN_MASK
)) {
654 if (atomic_read(&ndev
->state
) == NCI_DISCOVERY
) {
655 /* A single target was found and activated
657 atomic_set(&ndev
->state
, NCI_POLL_ACTIVE
);
658 if (err
== NCI_STATUS_OK
)
659 nci_target_auto_activated(ndev
, &ntf
);
660 } else { /* ndev->state == NCI_W4_HOST_SELECT */
661 /* A selected target was activated, so complete the
663 atomic_set(&ndev
->state
, NCI_POLL_ACTIVE
);
664 nci_req_complete(ndev
, err
);
669 atomic_set(&ndev
->state
, NCI_LISTEN_ACTIVE
);
670 if (err
== NCI_STATUS_OK
&&
671 ntf
.rf_protocol
== NCI_RF_PROTOCOL_NFC_DEP
) {
672 err
= nfc_tm_activated(ndev
->nfc_dev
,
673 NFC_PROTO_NFC_DEP_MASK
,
676 ndev
->remote_gb_len
);
677 if (err
!= NCI_STATUS_OK
)
678 pr_err("error when signaling tm activation\n");
683 static void nci_rf_deactivate_ntf_packet(struct nci_dev
*ndev
,
686 struct nci_conn_info
*conn_info
;
687 struct nci_rf_deactivate_ntf
*ntf
= (void *) skb
->data
;
689 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf
->type
, ntf
->reason
);
691 conn_info
= ndev
->rf_conn_info
;
695 /* drop tx data queue */
696 skb_queue_purge(&ndev
->tx_q
);
698 /* drop partial rx data packet */
699 if (ndev
->rx_data_reassembly
) {
700 kfree_skb(ndev
->rx_data_reassembly
);
701 ndev
->rx_data_reassembly
= NULL
;
704 /* complete the data exchange transaction, if exists */
705 if (test_bit(NCI_DATA_EXCHANGE
, &ndev
->flags
))
706 nci_data_exchange_complete(ndev
, NULL
, NCI_STATIC_RF_CONN_ID
,
710 case NCI_DEACTIVATE_TYPE_IDLE_MODE
:
711 nci_clear_target_list(ndev
);
712 atomic_set(&ndev
->state
, NCI_IDLE
);
714 case NCI_DEACTIVATE_TYPE_SLEEP_MODE
:
715 case NCI_DEACTIVATE_TYPE_SLEEP_AF_MODE
:
716 atomic_set(&ndev
->state
, NCI_W4_HOST_SELECT
);
718 case NCI_DEACTIVATE_TYPE_DISCOVERY
:
719 nci_clear_target_list(ndev
);
720 atomic_set(&ndev
->state
, NCI_DISCOVERY
);
724 nci_req_complete(ndev
, NCI_STATUS_OK
);
727 static void nci_nfcee_discover_ntf_packet(struct nci_dev
*ndev
,
730 u8 status
= NCI_STATUS_OK
;
731 struct nci_nfcee_discover_ntf
*nfcee_ntf
=
732 (struct nci_nfcee_discover_ntf
*)skb
->data
;
736 /* NFCForum NCI 9.2.1 HCI Network Specific Handling
737 * If the NFCC supports the HCI Network, it SHALL return one,
738 * and only one, NFCEE_DISCOVER_NTF with a Protocol type of
739 * “HCI Access”, even if the HCI Network contains multiple NFCEEs.
741 ndev
->hci_dev
->nfcee_id
= nfcee_ntf
->nfcee_id
;
742 ndev
->cur_params
.id
= nfcee_ntf
->nfcee_id
;
744 nci_req_complete(ndev
, status
);
747 static void nci_nfcee_action_ntf_packet(struct nci_dev
*ndev
,
753 void nci_ntf_packet(struct nci_dev
*ndev
, struct sk_buff
*skb
)
755 __u16 ntf_opcode
= nci_opcode(skb
->data
);
757 pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
759 nci_opcode_gid(ntf_opcode
),
760 nci_opcode_oid(ntf_opcode
),
761 nci_plen(skb
->data
));
763 /* strip the nci control header */
764 skb_pull(skb
, NCI_CTRL_HDR_SIZE
);
766 if (nci_opcode_gid(ntf_opcode
) == NCI_GID_PROPRIETARY
) {
767 if (nci_prop_ntf_packet(ndev
, ntf_opcode
, skb
) == -ENOTSUPP
) {
768 pr_err("unsupported ntf opcode 0x%x\n",
775 switch (ntf_opcode
) {
776 case NCI_OP_CORE_RESET_NTF
:
777 nci_core_reset_ntf_packet(ndev
, skb
);
780 case NCI_OP_CORE_CONN_CREDITS_NTF
:
781 nci_core_conn_credits_ntf_packet(ndev
, skb
);
784 case NCI_OP_CORE_GENERIC_ERROR_NTF
:
785 nci_core_generic_error_ntf_packet(ndev
, skb
);
788 case NCI_OP_CORE_INTF_ERROR_NTF
:
789 nci_core_conn_intf_error_ntf_packet(ndev
, skb
);
792 case NCI_OP_RF_DISCOVER_NTF
:
793 nci_rf_discover_ntf_packet(ndev
, skb
);
796 case NCI_OP_RF_INTF_ACTIVATED_NTF
:
797 nci_rf_intf_activated_ntf_packet(ndev
, skb
);
800 case NCI_OP_RF_DEACTIVATE_NTF
:
801 nci_rf_deactivate_ntf_packet(ndev
, skb
);
804 case NCI_OP_NFCEE_DISCOVER_NTF
:
805 nci_nfcee_discover_ntf_packet(ndev
, skb
);
808 case NCI_OP_RF_NFCEE_ACTION_NTF
:
809 nci_nfcee_action_ntf_packet(ndev
, skb
);
813 pr_err("unknown ntf opcode 0x%x\n", ntf_opcode
);
817 nci_core_ntf_packet(ndev
, ntf_opcode
, skb
);