Skip to content

Commit 7d0911c

Browse files
Thierry EscandeSamuel Ortiz
authored andcommitted
NFC Digital: Add initiator NFC-DEP support
This adds support for NFC-DEP protocol in initiator mode for NFC-A and NFC-F technologies. When a target is detected, the process flow is as follow: For NFC-A technology: 1 - The digital stack receives a SEL_RES as the reply of the SEL_REQ command. 2 - If b7 of SEL_RES is set, the peer device is configure for NFC-DEP protocol. NFC core is notified through nfc_targets_found(). Execution continues at step 4. 3 - Otherwise, it's a tag and the NFC core is notified. Detection ends. 4 - The digital stacks sends an ATR_REQ command containing a randomly generated NFCID3 and the general bytes obtained from the LLCP layer of NFC core. For NFC-F technology: 1 - The digital stack receives a SENSF_RES as the reply of the SENSF_REQ command. 2 - If B1 and B2 of NFCID2 are 0x01 and 0xFE respectively, the peer device is configured for NFC-DEP protocol. NFC core is notified through nfc_targets_found(). Execution continues at step 4. 3 - Otherwise it's a type 3 tag. NFC core is notified. Detection ends. 4 - The digital stacks sends an ATR_REQ command containing the NFC-F NFCID2 as NFCID3 and the general bytes obtained from the LLCP layer of NFC core. For both technologies: 5 - The digital stacks receives the ATR_RES response containing the NFCID3 and the general bytes of the peer device. 6 - The digital stack notifies NFC core that the DEP link is up through nfc_dep_link_up(). 7 - The NFC core performs data exchange through tm_transceive(). 8 - The digital stack sends a DEP_REQ command containing an I PDU with the data from NFC core. 9 - The digital stack receives a DEP_RES command 10 - If the DEP_RES response contains a supervisor PDU with timeout extension request (RTOX) the digital stack sends a DEP_REQ command containing a supervisor PDU acknowledging the RTOX request. The execution continues at step 9. 11 - If the DEP_RES response contains an I PDU, the response data is passed back to NFC core through the response callback. The execution continues at step 8. Signed-off-by: Thierry Escande <thierry.escande@linux.intel.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent 8c0695e commit 7d0911c

5 files changed

Lines changed: 435 additions & 6 deletions

File tree

‎net/nfc/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ obj-$(CONFIG_NFC_DIGITAL) += nfc_digital.o
1010
nfc-objs := core.o netlink.o af_nfc.o rawsock.o llcp_core.o llcp_commands.o \
1111
llcp_sock.o
1212

13-
nfc_digital-objs := digital_core.o digital_technology.o
13+
nfc_digital-objs := digital_core.o digital_technology.o digital_dep.o

‎net/nfc/digital.h‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@
3535
#define DIGITAL_MAX_HEADER_LEN 7
3636
#define DIGITAL_CRC_LEN 2
3737

38+
#define DIGITAL_SENSF_NFCID2_NFC_DEP_B1 0x01
39+
#define DIGITAL_SENSF_NFCID2_NFC_DEP_B2 0xFE
40+
41+
#define DIGITAL_SENS_RES_NFC_DEP 0x0100
42+
#define DIGITAL_SEL_RES_NFC_DEP 0x40
43+
#define DIGITAL_SENSF_FELICA_SC 0xFFFF
44+
3845
#define DIGITAL_DRV_CAPS_IN_CRC(ddev) \
3946
((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_IN_CRC)
4047
#define DIGITAL_DRV_CAPS_TG_CRC(ddev) \
@@ -72,6 +79,13 @@ int digital_target_found(struct nfc_digital_dev *ddev,
7279

7380
int digital_in_recv_mifare_res(struct sk_buff *resp);
7481

82+
int digital_in_send_atr_req(struct nfc_digital_dev *ddev,
83+
struct nfc_target *target, __u8 comm_mode, __u8 *gb,
84+
size_t gb_len);
85+
int digital_in_send_dep_req(struct nfc_digital_dev *ddev,
86+
struct nfc_target *target, struct sk_buff *skb,
87+
struct digital_data_exch *data_exch);
88+
7589
typedef u16 (*crc_func_t)(u16, const u8 *, size_t);
7690

7791
#define CRC_A_INIT 0x6363

‎net/nfc/digital_core.c‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
#include "digital.h"
1919

2020
#define DIGITAL_PROTO_NFCA_RF_TECH \
21-
(NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK)
21+
(NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK | NFC_PROTO_NFC_DEP_MASK)
2222

23-
#define DIGITAL_PROTO_NFCF_RF_TECH (NFC_PROTO_FELICA_MASK)
23+
#define DIGITAL_PROTO_NFCF_RF_TECH \
24+
(NFC_PROTO_FELICA_MASK | NFC_PROTO_NFC_DEP_MASK)
2425

2526
struct digital_cmd {
2627
struct list_head queue;
@@ -260,6 +261,18 @@ int digital_target_found(struct nfc_digital_dev *ddev,
260261
add_crc = digital_skb_add_crc_f;
261262
break;
262263

264+
case NFC_PROTO_NFC_DEP:
265+
if (rf_tech == NFC_DIGITAL_RF_TECH_106A) {
266+
framing = NFC_DIGITAL_FRAMING_NFCA_NFC_DEP;
267+
check_crc = digital_skb_check_crc_a;
268+
add_crc = digital_skb_add_crc_a;
269+
} else {
270+
framing = NFC_DIGITAL_FRAMING_NFCF_NFC_DEP;
271+
check_crc = digital_skb_check_crc_f;
272+
add_crc = digital_skb_add_crc_f;
273+
}
274+
break;
275+
263276
default:
264277
PR_ERR("Invalid protocol %d", protocol);
265278
return -EINVAL;
@@ -453,12 +466,18 @@ static int digital_dep_link_up(struct nfc_dev *nfc_dev,
453466
struct nfc_target *target,
454467
__u8 comm_mode, __u8 *gb, size_t gb_len)
455468
{
456-
return -EOPNOTSUPP;
469+
struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
470+
471+
return digital_in_send_atr_req(ddev, target, comm_mode, gb, gb_len);
457472
}
458473

459474
static int digital_dep_link_down(struct nfc_dev *nfc_dev)
460475
{
461-
return -EOPNOTSUPP;
476+
struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
477+
478+
ddev->curr_protocol = 0;
479+
480+
return 0;
462481
}
463482

464483
static int digital_activate_target(struct nfc_dev *nfc_dev,
@@ -523,6 +542,9 @@ static int digital_in_send(struct nfc_dev *nfc_dev, struct nfc_target *target,
523542
data_exch->cb = cb;
524543
data_exch->cb_context = cb_context;
525544

545+
if (ddev->curr_protocol == NFC_PROTO_NFC_DEP)
546+
return digital_in_send_dep_req(ddev, target, skb, data_exch);
547+
526548
ddev->skb_add_crc(skb);
527549

528550
return digital_in_send_cmd(ddev, skb, 500, digital_in_send_complete,
@@ -578,6 +600,8 @@ struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops,
578600
ddev->protocols |= NFC_PROTO_MIFARE_MASK;
579601
if (supported_protocols & NFC_PROTO_FELICA_MASK)
580602
ddev->protocols |= NFC_PROTO_FELICA_MASK;
603+
if (supported_protocols & NFC_PROTO_NFC_DEP_MASK)
604+
ddev->protocols |= NFC_PROTO_NFC_DEP_MASK;
581605

582606
ddev->tx_headroom = tx_headroom + DIGITAL_MAX_HEADER_LEN;
583607
ddev->tx_tailroom = tx_tailroom + DIGITAL_CRC_LEN;

0 commit comments

Comments
 (0)