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
> 0) {
222 memcpy(target
->nfcid1
, nfca_poll
->nfcid1
,
225 } else if (rf_tech_and_mode
== NCI_NFC_B_PASSIVE_POLL_MODE
) {
226 nfcb_poll
= (struct rf_tech_specific_params_nfcb_poll
*)params
;
228 target
->sensb_res_len
= nfcb_poll
->sensb_res_len
;
229 if (target
->sensb_res_len
> 0) {
230 memcpy(target
->sensb_res
, nfcb_poll
->sensb_res
,
231 target
->sensb_res_len
);
233 } else if (rf_tech_and_mode
== NCI_NFC_F_PASSIVE_POLL_MODE
) {
234 nfcf_poll
= (struct rf_tech_specific_params_nfcf_poll
*)params
;
236 target
->sensf_res_len
= nfcf_poll
->sensf_res_len
;
237 if (target
->sensf_res_len
> 0) {
238 memcpy(target
->sensf_res
, nfcf_poll
->sensf_res
,
239 target
->sensf_res_len
);
241 } else if (rf_tech_and_mode
== NCI_NFC_V_PASSIVE_POLL_MODE
) {
242 nfcv_poll
= (struct rf_tech_specific_params_nfcv_poll
*)params
;
244 target
->is_iso15693
= 1;
245 target
->iso15693_dsfid
= nfcv_poll
->dsfid
;
246 memcpy(target
->iso15693_uid
, nfcv_poll
->uid
, NFC_ISO15693_UID_MAXSIZE
);
248 pr_err("unsupported rf_tech_and_mode 0x%x\n", rf_tech_and_mode
);
252 target
->supported_protocols
|= protocol
;
254 pr_debug("protocol 0x%x\n", protocol
);
259 static void nci_add_new_target(struct nci_dev
*ndev
,
260 struct nci_rf_discover_ntf
*ntf
)
262 struct nfc_target
*target
;
265 for (i
= 0; i
< ndev
->n_targets
; i
++) {
266 target
= &ndev
->targets
[i
];
267 if (target
->logical_idx
== ntf
->rf_discovery_id
) {
268 /* This target already exists, add the new protocol */
269 nci_add_new_protocol(ndev
, target
, ntf
->rf_protocol
,
270 ntf
->rf_tech_and_mode
,
271 &ntf
->rf_tech_specific_params
);
276 /* This is a new target, check if we've enough room */
277 if (ndev
->n_targets
== NCI_MAX_DISCOVERED_TARGETS
) {
278 pr_debug("not enough room, ignoring new target...\n");
282 target
= &ndev
->targets
[ndev
->n_targets
];
284 rc
= nci_add_new_protocol(ndev
, target
, ntf
->rf_protocol
,
285 ntf
->rf_tech_and_mode
,
286 &ntf
->rf_tech_specific_params
);
288 target
->logical_idx
= ntf
->rf_discovery_id
;
291 pr_debug("logical idx %d, n_targets %d\n", target
->logical_idx
,
296 void nci_clear_target_list(struct nci_dev
*ndev
)
298 memset(ndev
->targets
, 0,
299 (sizeof(struct nfc_target
)*NCI_MAX_DISCOVERED_TARGETS
));
304 static void nci_rf_discover_ntf_packet(struct nci_dev
*ndev
,
307 struct nci_rf_discover_ntf ntf
;
308 __u8
*data
= skb
->data
;
309 bool add_target
= true;
311 ntf
.rf_discovery_id
= *data
++;
312 ntf
.rf_protocol
= *data
++;
313 ntf
.rf_tech_and_mode
= *data
++;
314 ntf
.rf_tech_specific_params_len
= *data
++;
316 pr_debug("rf_discovery_id %d\n", ntf
.rf_discovery_id
);
317 pr_debug("rf_protocol 0x%x\n", ntf
.rf_protocol
);
318 pr_debug("rf_tech_and_mode 0x%x\n", ntf
.rf_tech_and_mode
);
319 pr_debug("rf_tech_specific_params_len %d\n",
320 ntf
.rf_tech_specific_params_len
);
322 if (ntf
.rf_tech_specific_params_len
> 0) {
323 switch (ntf
.rf_tech_and_mode
) {
324 case NCI_NFC_A_PASSIVE_POLL_MODE
:
325 data
= nci_extract_rf_params_nfca_passive_poll(ndev
,
326 &(ntf
.rf_tech_specific_params
.nfca_poll
), data
);
329 case NCI_NFC_B_PASSIVE_POLL_MODE
:
330 data
= nci_extract_rf_params_nfcb_passive_poll(ndev
,
331 &(ntf
.rf_tech_specific_params
.nfcb_poll
), data
);
334 case NCI_NFC_F_PASSIVE_POLL_MODE
:
335 data
= nci_extract_rf_params_nfcf_passive_poll(ndev
,
336 &(ntf
.rf_tech_specific_params
.nfcf_poll
), data
);
339 case NCI_NFC_V_PASSIVE_POLL_MODE
:
340 data
= nci_extract_rf_params_nfcv_passive_poll(ndev
,
341 &(ntf
.rf_tech_specific_params
.nfcv_poll
), data
);
345 pr_err("unsupported rf_tech_and_mode 0x%x\n",
346 ntf
.rf_tech_and_mode
);
347 data
+= ntf
.rf_tech_specific_params_len
;
352 ntf
.ntf_type
= *data
++;
353 pr_debug("ntf_type %d\n", ntf
.ntf_type
);
355 if (add_target
== true)
356 nci_add_new_target(ndev
, &ntf
);
358 if (ntf
.ntf_type
== NCI_DISCOVER_NTF_TYPE_MORE
) {
359 atomic_set(&ndev
->state
, NCI_W4_ALL_DISCOVERIES
);
361 atomic_set(&ndev
->state
, NCI_W4_HOST_SELECT
);
362 nfc_targets_found(ndev
->nfc_dev
, ndev
->targets
,
367 static int nci_extract_activation_params_iso_dep(struct nci_dev
*ndev
,
368 struct nci_rf_intf_activated_ntf
*ntf
, __u8
*data
)
370 struct activation_params_nfca_poll_iso_dep
*nfca_poll
;
371 struct activation_params_nfcb_poll_iso_dep
*nfcb_poll
;
373 switch (ntf
->activation_rf_tech_and_mode
) {
374 case NCI_NFC_A_PASSIVE_POLL_MODE
:
375 nfca_poll
= &ntf
->activation_params
.nfca_poll_iso_dep
;
376 nfca_poll
->rats_res_len
= min_t(__u8
, *data
++, 20);
377 pr_debug("rats_res_len %d\n", nfca_poll
->rats_res_len
);
378 if (nfca_poll
->rats_res_len
> 0) {
379 memcpy(nfca_poll
->rats_res
,
380 data
, nfca_poll
->rats_res_len
);
384 case NCI_NFC_B_PASSIVE_POLL_MODE
:
385 nfcb_poll
= &ntf
->activation_params
.nfcb_poll_iso_dep
;
386 nfcb_poll
->attrib_res_len
= min_t(__u8
, *data
++, 50);
387 pr_debug("attrib_res_len %d\n", nfcb_poll
->attrib_res_len
);
388 if (nfcb_poll
->attrib_res_len
> 0) {
389 memcpy(nfcb_poll
->attrib_res
,
390 data
, nfcb_poll
->attrib_res_len
);
395 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
396 ntf
->activation_rf_tech_and_mode
);
397 return NCI_STATUS_RF_PROTOCOL_ERROR
;
400 return NCI_STATUS_OK
;
403 static int nci_extract_activation_params_nfc_dep(struct nci_dev
*ndev
,
404 struct nci_rf_intf_activated_ntf
*ntf
, __u8
*data
)
406 struct activation_params_poll_nfc_dep
*poll
;
407 struct activation_params_listen_nfc_dep
*listen
;
409 switch (ntf
->activation_rf_tech_and_mode
) {
410 case NCI_NFC_A_PASSIVE_POLL_MODE
:
411 case NCI_NFC_F_PASSIVE_POLL_MODE
:
412 poll
= &ntf
->activation_params
.poll_nfc_dep
;
413 poll
->atr_res_len
= min_t(__u8
, *data
++,
414 NFC_ATR_RES_MAXSIZE
- 2);
415 pr_debug("atr_res_len %d\n", poll
->atr_res_len
);
416 if (poll
->atr_res_len
> 0)
417 memcpy(poll
->atr_res
, data
, poll
->atr_res_len
);
420 case NCI_NFC_A_PASSIVE_LISTEN_MODE
:
421 case NCI_NFC_F_PASSIVE_LISTEN_MODE
:
422 listen
= &ntf
->activation_params
.listen_nfc_dep
;
423 listen
->atr_req_len
= min_t(__u8
, *data
++,
424 NFC_ATR_REQ_MAXSIZE
- 2);
425 pr_debug("atr_req_len %d\n", listen
->atr_req_len
);
426 if (listen
->atr_req_len
> 0)
427 memcpy(listen
->atr_req
, data
, listen
->atr_req_len
);
431 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
432 ntf
->activation_rf_tech_and_mode
);
433 return NCI_STATUS_RF_PROTOCOL_ERROR
;
436 return NCI_STATUS_OK
;
439 static void nci_target_auto_activated(struct nci_dev
*ndev
,
440 struct nci_rf_intf_activated_ntf
*ntf
)
442 struct nfc_target
*target
;
445 target
= &ndev
->targets
[ndev
->n_targets
];
447 rc
= nci_add_new_protocol(ndev
, target
, ntf
->rf_protocol
,
448 ntf
->activation_rf_tech_and_mode
,
449 &ntf
->rf_tech_specific_params
);
453 target
->logical_idx
= ntf
->rf_discovery_id
;
456 pr_debug("logical idx %d, n_targets %d\n",
457 target
->logical_idx
, ndev
->n_targets
);
459 nfc_targets_found(ndev
->nfc_dev
, ndev
->targets
, ndev
->n_targets
);
462 static int nci_store_general_bytes_nfc_dep(struct nci_dev
*ndev
,
463 struct nci_rf_intf_activated_ntf
*ntf
)
465 ndev
->remote_gb_len
= 0;
467 if (ntf
->activation_params_len
<= 0)
468 return NCI_STATUS_OK
;
470 switch (ntf
->activation_rf_tech_and_mode
) {
471 case NCI_NFC_A_PASSIVE_POLL_MODE
:
472 case NCI_NFC_F_PASSIVE_POLL_MODE
:
473 ndev
->remote_gb_len
= min_t(__u8
,
474 (ntf
->activation_params
.poll_nfc_dep
.atr_res_len
475 - NFC_ATR_RES_GT_OFFSET
),
476 NFC_ATR_RES_GB_MAXSIZE
);
477 memcpy(ndev
->remote_gb
,
478 (ntf
->activation_params
.poll_nfc_dep
.atr_res
479 + NFC_ATR_RES_GT_OFFSET
),
480 ndev
->remote_gb_len
);
483 case NCI_NFC_A_PASSIVE_LISTEN_MODE
:
484 case NCI_NFC_F_PASSIVE_LISTEN_MODE
:
485 ndev
->remote_gb_len
= min_t(__u8
,
486 (ntf
->activation_params
.listen_nfc_dep
.atr_req_len
487 - NFC_ATR_REQ_GT_OFFSET
),
488 NFC_ATR_REQ_GB_MAXSIZE
);
489 memcpy(ndev
->remote_gb
,
490 (ntf
->activation_params
.listen_nfc_dep
.atr_req
491 + NFC_ATR_REQ_GT_OFFSET
),
492 ndev
->remote_gb_len
);
496 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
497 ntf
->activation_rf_tech_and_mode
);
498 return NCI_STATUS_RF_PROTOCOL_ERROR
;
501 return NCI_STATUS_OK
;
504 static void nci_rf_intf_activated_ntf_packet(struct nci_dev
*ndev
,
507 struct nci_conn_info
*conn_info
;
508 struct nci_rf_intf_activated_ntf ntf
;
509 __u8
*data
= skb
->data
;
510 int err
= NCI_STATUS_OK
;
512 ntf
.rf_discovery_id
= *data
++;
513 ntf
.rf_interface
= *data
++;
514 ntf
.rf_protocol
= *data
++;
515 ntf
.activation_rf_tech_and_mode
= *data
++;
516 ntf
.max_data_pkt_payload_size
= *data
++;
517 ntf
.initial_num_credits
= *data
++;
518 ntf
.rf_tech_specific_params_len
= *data
++;
520 pr_debug("rf_discovery_id %d\n", ntf
.rf_discovery_id
);
521 pr_debug("rf_interface 0x%x\n", ntf
.rf_interface
);
522 pr_debug("rf_protocol 0x%x\n", ntf
.rf_protocol
);
523 pr_debug("activation_rf_tech_and_mode 0x%x\n",
524 ntf
.activation_rf_tech_and_mode
);
525 pr_debug("max_data_pkt_payload_size 0x%x\n",
526 ntf
.max_data_pkt_payload_size
);
527 pr_debug("initial_num_credits 0x%x\n",
528 ntf
.initial_num_credits
);
529 pr_debug("rf_tech_specific_params_len %d\n",
530 ntf
.rf_tech_specific_params_len
);
532 /* If this contains a value of 0x00 (NFCEE Direct RF
533 * Interface) then all following parameters SHALL contain a
534 * value of 0 and SHALL be ignored.
536 if (ntf
.rf_interface
== NCI_RF_INTERFACE_NFCEE_DIRECT
)
539 if (ntf
.rf_tech_specific_params_len
> 0) {
540 switch (ntf
.activation_rf_tech_and_mode
) {
541 case NCI_NFC_A_PASSIVE_POLL_MODE
:
542 data
= nci_extract_rf_params_nfca_passive_poll(ndev
,
543 &(ntf
.rf_tech_specific_params
.nfca_poll
), data
);
546 case NCI_NFC_B_PASSIVE_POLL_MODE
:
547 data
= nci_extract_rf_params_nfcb_passive_poll(ndev
,
548 &(ntf
.rf_tech_specific_params
.nfcb_poll
), data
);
551 case NCI_NFC_F_PASSIVE_POLL_MODE
:
552 data
= nci_extract_rf_params_nfcf_passive_poll(ndev
,
553 &(ntf
.rf_tech_specific_params
.nfcf_poll
), data
);
556 case NCI_NFC_V_PASSIVE_POLL_MODE
:
557 data
= nci_extract_rf_params_nfcv_passive_poll(ndev
,
558 &(ntf
.rf_tech_specific_params
.nfcv_poll
), data
);
561 case NCI_NFC_A_PASSIVE_LISTEN_MODE
:
562 /* no RF technology specific parameters */
565 case NCI_NFC_F_PASSIVE_LISTEN_MODE
:
566 data
= nci_extract_rf_params_nfcf_passive_listen(ndev
,
567 &(ntf
.rf_tech_specific_params
.nfcf_listen
),
572 pr_err("unsupported activation_rf_tech_and_mode 0x%x\n",
573 ntf
.activation_rf_tech_and_mode
);
574 err
= NCI_STATUS_RF_PROTOCOL_ERROR
;
579 ntf
.data_exch_rf_tech_and_mode
= *data
++;
580 ntf
.data_exch_tx_bit_rate
= *data
++;
581 ntf
.data_exch_rx_bit_rate
= *data
++;
582 ntf
.activation_params_len
= *data
++;
584 pr_debug("data_exch_rf_tech_and_mode 0x%x\n",
585 ntf
.data_exch_rf_tech_and_mode
);
586 pr_debug("data_exch_tx_bit_rate 0x%x\n", ntf
.data_exch_tx_bit_rate
);
587 pr_debug("data_exch_rx_bit_rate 0x%x\n", ntf
.data_exch_rx_bit_rate
);
588 pr_debug("activation_params_len %d\n", ntf
.activation_params_len
);
590 if (ntf
.activation_params_len
> 0) {
591 switch (ntf
.rf_interface
) {
592 case NCI_RF_INTERFACE_ISO_DEP
:
593 err
= nci_extract_activation_params_iso_dep(ndev
,
597 case NCI_RF_INTERFACE_NFC_DEP
:
598 err
= nci_extract_activation_params_nfc_dep(ndev
,
602 case NCI_RF_INTERFACE_FRAME
:
603 /* no activation params */
607 pr_err("unsupported rf_interface 0x%x\n",
609 err
= NCI_STATUS_RF_PROTOCOL_ERROR
;
615 if (err
== NCI_STATUS_OK
) {
616 conn_info
= ndev
->rf_conn_info
;
620 conn_info
->max_pkt_payload_len
= ntf
.max_data_pkt_payload_size
;
621 conn_info
->initial_num_credits
= ntf
.initial_num_credits
;
623 /* set the available credits to initial value */
624 atomic_set(&conn_info
->credits_cnt
,
625 conn_info
->initial_num_credits
);
627 /* store general bytes to be reported later in dep_link_up */
628 if (ntf
.rf_interface
== NCI_RF_INTERFACE_NFC_DEP
) {
629 err
= nci_store_general_bytes_nfc_dep(ndev
, &ntf
);
630 if (err
!= NCI_STATUS_OK
)
631 pr_err("unable to store general bytes\n");
635 if (!(ntf
.activation_rf_tech_and_mode
& NCI_RF_TECH_MODE_LISTEN_MASK
)) {
637 if (atomic_read(&ndev
->state
) == NCI_DISCOVERY
) {
638 /* A single target was found and activated
640 atomic_set(&ndev
->state
, NCI_POLL_ACTIVE
);
641 if (err
== NCI_STATUS_OK
)
642 nci_target_auto_activated(ndev
, &ntf
);
643 } else { /* ndev->state == NCI_W4_HOST_SELECT */
644 /* A selected target was activated, so complete the
646 atomic_set(&ndev
->state
, NCI_POLL_ACTIVE
);
647 nci_req_complete(ndev
, err
);
652 atomic_set(&ndev
->state
, NCI_LISTEN_ACTIVE
);
653 if (err
== NCI_STATUS_OK
&&
654 ntf
.rf_protocol
== NCI_RF_PROTOCOL_NFC_DEP
) {
655 err
= nfc_tm_activated(ndev
->nfc_dev
,
656 NFC_PROTO_NFC_DEP_MASK
,
659 ndev
->remote_gb_len
);
660 if (err
!= NCI_STATUS_OK
)
661 pr_err("error when signaling tm activation\n");
666 static void nci_rf_deactivate_ntf_packet(struct nci_dev
*ndev
,
669 struct nci_conn_info
*conn_info
;
670 struct nci_rf_deactivate_ntf
*ntf
= (void *) skb
->data
;
672 pr_debug("entry, type 0x%x, reason 0x%x\n", ntf
->type
, ntf
->reason
);
674 conn_info
= ndev
->rf_conn_info
;
678 /* drop tx data queue */
679 skb_queue_purge(&ndev
->tx_q
);
681 /* drop partial rx data packet */
682 if (ndev
->rx_data_reassembly
) {
683 kfree_skb(ndev
->rx_data_reassembly
);
684 ndev
->rx_data_reassembly
= NULL
;
687 /* complete the data exchange transaction, if exists */
688 if (test_bit(NCI_DATA_EXCHANGE
, &ndev
->flags
))
689 nci_data_exchange_complete(ndev
, NULL
, NCI_STATIC_RF_CONN_ID
,
693 case NCI_DEACTIVATE_TYPE_IDLE_MODE
:
694 nci_clear_target_list(ndev
);
695 atomic_set(&ndev
->state
, NCI_IDLE
);
697 case NCI_DEACTIVATE_TYPE_SLEEP_MODE
:
698 case NCI_DEACTIVATE_TYPE_SLEEP_AF_MODE
:
699 atomic_set(&ndev
->state
, NCI_W4_HOST_SELECT
);
701 case NCI_DEACTIVATE_TYPE_DISCOVERY
:
702 nci_clear_target_list(ndev
);
703 atomic_set(&ndev
->state
, NCI_DISCOVERY
);
707 nci_req_complete(ndev
, NCI_STATUS_OK
);
710 static void nci_nfcee_discover_ntf_packet(struct nci_dev
*ndev
,
713 u8 status
= NCI_STATUS_OK
;
714 struct nci_nfcee_discover_ntf
*nfcee_ntf
=
715 (struct nci_nfcee_discover_ntf
*)skb
->data
;
719 /* NFCForum NCI 9.2.1 HCI Network Specific Handling
720 * If the NFCC supports the HCI Network, it SHALL return one,
721 * and only one, NFCEE_DISCOVER_NTF with a Protocol type of
722 * “HCI Access”, even if the HCI Network contains multiple NFCEEs.
724 ndev
->hci_dev
->nfcee_id
= nfcee_ntf
->nfcee_id
;
725 ndev
->cur_params
.id
= nfcee_ntf
->nfcee_id
;
727 nci_req_complete(ndev
, status
);
730 static void nci_nfcee_action_ntf_packet(struct nci_dev
*ndev
,
736 void nci_ntf_packet(struct nci_dev
*ndev
, struct sk_buff
*skb
)
738 __u16 ntf_opcode
= nci_opcode(skb
->data
);
740 pr_debug("NCI RX: MT=ntf, PBF=%d, GID=0x%x, OID=0x%x, plen=%d\n",
742 nci_opcode_gid(ntf_opcode
),
743 nci_opcode_oid(ntf_opcode
),
744 nci_plen(skb
->data
));
746 /* strip the nci control header */
747 skb_pull(skb
, NCI_CTRL_HDR_SIZE
);
749 if (nci_opcode_gid(ntf_opcode
) == NCI_GID_PROPRIETARY
) {
750 if (nci_prop_ntf_packet(ndev
, ntf_opcode
, skb
) == -ENOTSUPP
) {
751 pr_err("unsupported ntf opcode 0x%x\n",
758 switch (ntf_opcode
) {
759 case NCI_OP_CORE_CONN_CREDITS_NTF
:
760 nci_core_conn_credits_ntf_packet(ndev
, skb
);
763 case NCI_OP_CORE_GENERIC_ERROR_NTF
:
764 nci_core_generic_error_ntf_packet(ndev
, skb
);
767 case NCI_OP_CORE_INTF_ERROR_NTF
:
768 nci_core_conn_intf_error_ntf_packet(ndev
, skb
);
771 case NCI_OP_RF_DISCOVER_NTF
:
772 nci_rf_discover_ntf_packet(ndev
, skb
);
775 case NCI_OP_RF_INTF_ACTIVATED_NTF
:
776 nci_rf_intf_activated_ntf_packet(ndev
, skb
);
779 case NCI_OP_RF_DEACTIVATE_NTF
:
780 nci_rf_deactivate_ntf_packet(ndev
, skb
);
783 case NCI_OP_NFCEE_DISCOVER_NTF
:
784 nci_nfcee_discover_ntf_packet(ndev
, skb
);
787 case NCI_OP_RF_NFCEE_ACTION_NTF
:
788 nci_nfcee_action_ntf_packet(ndev
, skb
);
792 pr_err("unknown ntf opcode 0x%x\n", ntf_opcode
);
796 nci_core_ntf_packet(ndev
, ntf_opcode
, skb
);