2 * NFC Digital Protocol stack
3 * Copyright (c) 2013, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #define pr_fmt(fmt) "digital: %s: " fmt, __func__
20 #define DIGITAL_CMD_SENS_REQ 0x26
21 #define DIGITAL_CMD_ALL_REQ 0x52
22 #define DIGITAL_CMD_SEL_REQ_CL1 0x93
23 #define DIGITAL_CMD_SEL_REQ_CL2 0x95
24 #define DIGITAL_CMD_SEL_REQ_CL3 0x97
26 #define DIGITAL_SDD_REQ_SEL_PAR 0x20
28 #define DIGITAL_SDD_RES_CT 0x88
29 #define DIGITAL_SDD_RES_LEN 5
30 #define DIGITAL_SEL_RES_LEN 1
32 #define DIGITAL_SEL_RES_NFCID1_COMPLETE(sel_res) (!((sel_res) & 0x04))
33 #define DIGITAL_SEL_RES_IS_T2T(sel_res) (!((sel_res) & 0x60))
34 #define DIGITAL_SEL_RES_IS_T4T(sel_res) ((sel_res) & 0x20)
35 #define DIGITAL_SEL_RES_IS_NFC_DEP(sel_res) ((sel_res) & 0x40)
37 #define DIGITAL_SENS_RES_IS_T1T(sens_res) (((sens_res) & 0x0C00) == 0x0C00)
38 #define DIGITAL_SENS_RES_IS_VALID(sens_res) \
39 ((!((sens_res) & 0x001F) && (((sens_res) & 0x0C00) == 0x0C00)) || \
40 (((sens_res) & 0x001F) && ((sens_res) & 0x0C00) != 0x0C00))
42 #define DIGITAL_MIFARE_READ_RES_LEN 16
43 #define DIGITAL_MIFARE_ACK_RES 0x0A
45 #define DIGITAL_CMD_SENSB_REQ 0x05
46 #define DIGITAL_SENSB_ADVANCED BIT(5)
47 #define DIGITAL_SENSB_EXTENDED BIT(4)
48 #define DIGITAL_SENSB_ALLB_REQ BIT(3)
49 #define DIGITAL_SENSB_N(n) ((n) & 0x7)
51 #define DIGITAL_CMD_SENSB_RES 0x50
53 #define DIGITAL_CMD_ATTRIB_REQ 0x1D
54 #define DIGITAL_ATTRIB_P1_TR0_DEFAULT (0x0 << 6)
55 #define DIGITAL_ATTRIB_P1_TR1_DEFAULT (0x0 << 4)
56 #define DIGITAL_ATTRIB_P1_SUPRESS_EOS BIT(3)
57 #define DIGITAL_ATTRIB_P1_SUPRESS_SOS BIT(2)
58 #define DIGITAL_ATTRIB_P2_LISTEN_POLL_1 (0x0 << 6)
59 #define DIGITAL_ATTRIB_P2_POLL_LISTEN_1 (0x0 << 4)
60 #define DIGITAL_ATTRIB_P2_MAX_FRAME_256 0x8
61 #define DIGITAL_ATTRIB_P4_DID(n) ((n) & 0xf)
63 #define DIGITAL_CMD_SENSF_REQ 0x00
64 #define DIGITAL_CMD_SENSF_RES 0x01
66 #define DIGITAL_SENSF_RES_MIN_LENGTH 17
67 #define DIGITAL_SENSF_RES_RD_AP_B1 0x00
68 #define DIGITAL_SENSF_RES_RD_AP_B2 0x8F
70 #define DIGITAL_SENSF_REQ_RC_NONE 0
71 #define DIGITAL_SENSF_REQ_RC_SC 1
72 #define DIGITAL_SENSF_REQ_RC_AP 2
74 #define DIGITAL_CMD_ISO15693_INVENTORY_REQ 0x01
76 #define DIGITAL_ISO15693_REQ_FLAG_DATA_RATE BIT(1)
77 #define DIGITAL_ISO15693_REQ_FLAG_INVENTORY BIT(2)
78 #define DIGITAL_ISO15693_REQ_FLAG_NB_SLOTS BIT(5)
79 #define DIGITAL_ISO15693_RES_FLAG_ERROR BIT(0)
80 #define DIGITAL_ISO15693_RES_IS_VALID(flags) \
81 (!((flags) & DIGITAL_ISO15693_RES_FLAG_ERROR))
83 #define DIGITAL_ISO_DEP_I_PCB 0x02
84 #define DIGITAL_ISO_DEP_PNI(pni) ((pni) & 0x01)
86 #define DIGITAL_ISO_DEP_PCB_TYPE(pcb) ((pcb) & 0xC0)
88 #define DIGITAL_ISO_DEP_I_BLOCK 0x00
90 #define DIGITAL_ISO_DEP_BLOCK_HAS_DID(pcb) ((pcb) & 0x08)
92 static const u8 digital_ats_fsc
[] = {
93 16, 24, 32, 40, 48, 64, 96, 128,
96 #define DIGITAL_ATS_FSCI(t0) ((t0) & 0x0F)
97 #define DIGITAL_SENSB_FSCI(pi2) (((pi2) & 0xF0) >> 4)
98 #define DIGITAL_ATS_MAX_FSC 256
100 #define DIGITAL_RATS_BYTE1 0xE0
101 #define DIGITAL_RATS_PARAM 0x80
103 struct digital_sdd_res
{
108 struct digital_sel_req
{
115 struct digital_sensb_req
{
121 struct digital_sensb_res
{
128 struct digital_attrib_req
{
137 struct digital_attrib_res
{
141 struct digital_sensf_req
{
149 struct digital_sensf_res
{
160 struct digital_iso15693_inv_req
{
167 struct digital_iso15693_inv_res
{
173 static int digital_in_send_sdd_req(struct nfc_digital_dev
*ddev
,
174 struct nfc_target
*target
);
176 int digital_in_iso_dep_pull_sod(struct nfc_digital_dev
*ddev
,
186 block_type
= DIGITAL_ISO_DEP_PCB_TYPE(pcb
);
188 /* No support fo R-block nor S-block */
189 if (block_type
!= DIGITAL_ISO_DEP_I_BLOCK
) {
190 pr_err("ISO_DEP R-block and S-block not supported\n");
194 if (DIGITAL_ISO_DEP_BLOCK_HAS_DID(pcb
)) {
195 pr_err("DID field in ISO_DEP PCB not supported\n");
204 int digital_in_iso_dep_push_sod(struct nfc_digital_dev
*ddev
,
208 * Chaining not supported so skb->len + 1 PCB byte + 2 CRC bytes must
209 * not be greater than remote FSC
211 if (skb
->len
+ 3 > ddev
->target_fsc
)
216 *skb
->data
= DIGITAL_ISO_DEP_I_PCB
| ddev
->curr_nfc_dep_pni
;
218 ddev
->curr_nfc_dep_pni
=
219 DIGITAL_ISO_DEP_PNI(ddev
->curr_nfc_dep_pni
+ 1);
224 static void digital_in_recv_ats(struct nfc_digital_dev
*ddev
, void *arg
,
225 struct sk_buff
*resp
)
227 struct nfc_target
*target
= arg
;
242 fsdi
= DIGITAL_ATS_FSCI(resp
->data
[1]);
244 ddev
->target_fsc
= DIGITAL_ATS_MAX_FSC
;
246 ddev
->target_fsc
= digital_ats_fsc
[fsdi
];
248 ddev
->curr_nfc_dep_pni
= 0;
250 rc
= digital_target_found(ddev
, target
, NFC_PROTO_ISO14443
);
257 digital_poll_next_tech(ddev
);
260 static int digital_in_send_rats(struct nfc_digital_dev
*ddev
,
261 struct nfc_target
*target
)
266 skb
= digital_skb_alloc(ddev
, 2);
270 skb_put_u8(skb
, DIGITAL_RATS_BYTE1
);
271 skb_put_u8(skb
, DIGITAL_RATS_PARAM
);
273 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_ats
,
281 static void digital_in_recv_sel_res(struct nfc_digital_dev
*ddev
, void *arg
,
282 struct sk_buff
*resp
)
284 struct nfc_target
*target
= arg
;
295 if (!DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
296 rc
= digital_skb_check_crc_a(resp
);
298 PROTOCOL_ERR("4.4.1.3");
303 if (resp
->len
!= DIGITAL_SEL_RES_LEN
) {
308 sel_res
= resp
->data
[0];
310 if (!DIGITAL_SEL_RES_NFCID1_COMPLETE(sel_res
)) {
311 rc
= digital_in_send_sdd_req(ddev
, target
);
318 target
->sel_res
= sel_res
;
320 if (DIGITAL_SEL_RES_IS_T2T(sel_res
)) {
321 nfc_proto
= NFC_PROTO_MIFARE
;
322 } else if (DIGITAL_SEL_RES_IS_NFC_DEP(sel_res
)) {
323 nfc_proto
= NFC_PROTO_NFC_DEP
;
324 } else if (DIGITAL_SEL_RES_IS_T4T(sel_res
)) {
325 rc
= digital_in_send_rats(ddev
, target
);
329 * Skip target_found and don't free it for now. This will be
330 * done when receiving the ATS
338 rc
= digital_target_found(ddev
, target
, nfc_proto
);
347 digital_poll_next_tech(ddev
);
350 static int digital_in_send_sel_req(struct nfc_digital_dev
*ddev
,
351 struct nfc_target
*target
,
352 struct digital_sdd_res
*sdd_res
)
355 struct digital_sel_req
*sel_req
;
359 skb
= digital_skb_alloc(ddev
, sizeof(struct digital_sel_req
));
363 skb_put(skb
, sizeof(struct digital_sel_req
));
364 sel_req
= (struct digital_sel_req
*)skb
->data
;
366 if (target
->nfcid1_len
<= 4)
367 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL1
;
368 else if (target
->nfcid1_len
< 10)
369 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL2
;
371 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL3
;
373 sel_req
->sel_cmd
= sel_cmd
;
375 memcpy(sel_req
->nfcid1
, sdd_res
->nfcid1
, 4);
376 sel_req
->bcc
= sdd_res
->bcc
;
378 if (DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
379 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
380 NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A
);
384 digital_skb_add_crc_a(skb
);
387 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sel_res
,
396 static void digital_in_recv_sdd_res(struct nfc_digital_dev
*ddev
, void *arg
,
397 struct sk_buff
*resp
)
399 struct nfc_target
*target
= arg
;
400 struct digital_sdd_res
*sdd_res
;
411 if (resp
->len
< DIGITAL_SDD_RES_LEN
) {
412 PROTOCOL_ERR("4.7.2.8");
417 sdd_res
= (struct digital_sdd_res
*)resp
->data
;
419 for (i
= 0, bcc
= 0; i
< 4; i
++)
420 bcc
^= sdd_res
->nfcid1
[i
];
422 if (bcc
!= sdd_res
->bcc
) {
423 PROTOCOL_ERR("4.7.2.6");
428 if (sdd_res
->nfcid1
[0] == DIGITAL_SDD_RES_CT
) {
436 memcpy(target
->nfcid1
+ target
->nfcid1_len
, sdd_res
->nfcid1
+ offset
,
438 target
->nfcid1_len
+= size
;
440 rc
= digital_in_send_sel_req(ddev
, target
, sdd_res
);
447 digital_poll_next_tech(ddev
);
451 static int digital_in_send_sdd_req(struct nfc_digital_dev
*ddev
,
452 struct nfc_target
*target
)
458 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
459 NFC_DIGITAL_FRAMING_NFCA_STANDARD
);
463 skb
= digital_skb_alloc(ddev
, 2);
467 if (target
->nfcid1_len
== 0)
468 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL1
;
469 else if (target
->nfcid1_len
== 3)
470 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL2
;
472 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL3
;
474 skb_put_u8(skb
, sel_cmd
);
475 skb_put_u8(skb
, DIGITAL_SDD_REQ_SEL_PAR
);
477 return digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sdd_res
,
481 static void digital_in_recv_sens_res(struct nfc_digital_dev
*ddev
, void *arg
,
482 struct sk_buff
*resp
)
484 struct nfc_target
*target
= NULL
;
493 if (resp
->len
< sizeof(u16
)) {
498 target
= kzalloc(sizeof(struct nfc_target
), GFP_KERNEL
);
504 target
->sens_res
= __le16_to_cpu(*(__le16
*)resp
->data
);
506 if (!DIGITAL_SENS_RES_IS_VALID(target
->sens_res
)) {
507 PROTOCOL_ERR("4.6.3.3");
512 if (DIGITAL_SENS_RES_IS_T1T(target
->sens_res
))
513 rc
= digital_target_found(ddev
, target
, NFC_PROTO_JEWEL
);
515 rc
= digital_in_send_sdd_req(ddev
, target
);
522 digital_poll_next_tech(ddev
);
526 int digital_in_send_sens_req(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
531 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
,
532 NFC_DIGITAL_RF_TECH_106A
);
536 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
537 NFC_DIGITAL_FRAMING_NFCA_SHORT
);
541 skb
= digital_skb_alloc(ddev
, 1);
545 skb_put_u8(skb
, DIGITAL_CMD_SENS_REQ
);
547 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sens_res
, NULL
);
554 int digital_in_recv_mifare_res(struct sk_buff
*resp
)
556 /* Successful READ command response is 16 data bytes + 2 CRC bytes long.
557 * Since the driver can't differentiate a ACK/NACK response from a valid
558 * READ response, the CRC calculation must be handled at digital level
559 * even if the driver supports it for this technology.
561 if (resp
->len
== DIGITAL_MIFARE_READ_RES_LEN
+ DIGITAL_CRC_LEN
) {
562 if (digital_skb_check_crc_a(resp
)) {
563 PROTOCOL_ERR("9.4.1.2");
570 /* ACK response (i.e. successful WRITE). */
571 if (resp
->len
== 1 && resp
->data
[0] == DIGITAL_MIFARE_ACK_RES
) {
576 /* NACK and any other responses are treated as error. */
580 static void digital_in_recv_attrib_res(struct nfc_digital_dev
*ddev
, void *arg
,
581 struct sk_buff
*resp
)
583 struct nfc_target
*target
= arg
;
584 struct digital_attrib_res
*attrib_res
;
593 if (resp
->len
< sizeof(*attrib_res
)) {
594 PROTOCOL_ERR("12.6.2");
599 attrib_res
= (struct digital_attrib_res
*)resp
->data
;
601 if (attrib_res
->mbli_did
& 0x0f) {
602 PROTOCOL_ERR("12.6.2.1");
607 rc
= digital_target_found(ddev
, target
, NFC_PROTO_ISO14443_B
);
614 digital_poll_next_tech(ddev
);
617 static int digital_in_send_attrib_req(struct nfc_digital_dev
*ddev
,
618 struct nfc_target
*target
,
619 struct digital_sensb_res
*sensb_res
)
621 struct digital_attrib_req
*attrib_req
;
625 skb
= digital_skb_alloc(ddev
, sizeof(*attrib_req
));
629 attrib_req
= skb_put(skb
, sizeof(*attrib_req
));
631 attrib_req
->cmd
= DIGITAL_CMD_ATTRIB_REQ
;
632 memcpy(attrib_req
->nfcid0
, sensb_res
->nfcid0
,
633 sizeof(attrib_req
->nfcid0
));
634 attrib_req
->param1
= DIGITAL_ATTRIB_P1_TR0_DEFAULT
|
635 DIGITAL_ATTRIB_P1_TR1_DEFAULT
;
636 attrib_req
->param2
= DIGITAL_ATTRIB_P2_LISTEN_POLL_1
|
637 DIGITAL_ATTRIB_P2_POLL_LISTEN_1
|
638 DIGITAL_ATTRIB_P2_MAX_FRAME_256
;
639 attrib_req
->param3
= sensb_res
->proto_info
[1] & 0x07;
640 attrib_req
->param4
= DIGITAL_ATTRIB_P4_DID(0);
642 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_attrib_res
,
650 static void digital_in_recv_sensb_res(struct nfc_digital_dev
*ddev
, void *arg
,
651 struct sk_buff
*resp
)
653 struct nfc_target
*target
= NULL
;
654 struct digital_sensb_res
*sensb_res
;
664 if (resp
->len
!= sizeof(*sensb_res
)) {
665 PROTOCOL_ERR("5.6.2.1");
670 sensb_res
= (struct digital_sensb_res
*)resp
->data
;
672 if (sensb_res
->cmd
!= DIGITAL_CMD_SENSB_RES
) {
673 PROTOCOL_ERR("5.6.2");
678 if (!(sensb_res
->proto_info
[1] & BIT(0))) {
679 PROTOCOL_ERR("5.6.2.12");
684 if (sensb_res
->proto_info
[1] & BIT(3)) {
685 PROTOCOL_ERR("5.6.2.16");
690 fsci
= DIGITAL_SENSB_FSCI(sensb_res
->proto_info
[1]);
692 ddev
->target_fsc
= DIGITAL_ATS_MAX_FSC
;
694 ddev
->target_fsc
= digital_ats_fsc
[fsci
];
696 target
= kzalloc(sizeof(struct nfc_target
), GFP_KERNEL
);
702 rc
= digital_in_send_attrib_req(ddev
, target
, sensb_res
);
709 digital_poll_next_tech(ddev
);
713 int digital_in_send_sensb_req(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
715 struct digital_sensb_req
*sensb_req
;
719 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
,
720 NFC_DIGITAL_RF_TECH_106B
);
724 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
725 NFC_DIGITAL_FRAMING_NFCB
);
729 skb
= digital_skb_alloc(ddev
, sizeof(*sensb_req
));
733 sensb_req
= skb_put(skb
, sizeof(*sensb_req
));
735 sensb_req
->cmd
= DIGITAL_CMD_SENSB_REQ
;
736 sensb_req
->afi
= 0x00; /* All families and sub-families */
737 sensb_req
->param
= DIGITAL_SENSB_N(0);
739 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sensb_res
,
747 static void digital_in_recv_sensf_res(struct nfc_digital_dev
*ddev
, void *arg
,
748 struct sk_buff
*resp
)
752 struct nfc_target target
;
753 struct digital_sensf_res
*sensf_res
;
761 if (resp
->len
< DIGITAL_SENSF_RES_MIN_LENGTH
) {
766 if (!DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
767 rc
= digital_skb_check_crc_f(resp
);
769 PROTOCOL_ERR("6.4.1.8");
776 memset(&target
, 0, sizeof(struct nfc_target
));
778 sensf_res
= (struct digital_sensf_res
*)resp
->data
;
780 memcpy(target
.sensf_res
, sensf_res
, resp
->len
);
781 target
.sensf_res_len
= resp
->len
;
783 memcpy(target
.nfcid2
, sensf_res
->nfcid2
, NFC_NFCID2_MAXSIZE
);
784 target
.nfcid2_len
= NFC_NFCID2_MAXSIZE
;
786 if (target
.nfcid2
[0] == DIGITAL_SENSF_NFCID2_NFC_DEP_B1
&&
787 target
.nfcid2
[1] == DIGITAL_SENSF_NFCID2_NFC_DEP_B2
)
788 proto
= NFC_PROTO_NFC_DEP
;
790 proto
= NFC_PROTO_FELICA
;
792 rc
= digital_target_found(ddev
, &target
, proto
);
798 digital_poll_next_tech(ddev
);
801 int digital_in_send_sensf_req(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
803 struct digital_sensf_req
*sensf_req
;
808 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
, rf_tech
);
812 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
813 NFC_DIGITAL_FRAMING_NFCF
);
817 size
= sizeof(struct digital_sensf_req
);
819 skb
= digital_skb_alloc(ddev
, size
);
825 sensf_req
= (struct digital_sensf_req
*)skb
->data
;
826 sensf_req
->cmd
= DIGITAL_CMD_SENSF_REQ
;
827 sensf_req
->sc1
= 0xFF;
828 sensf_req
->sc2
= 0xFF;
832 *(u8
*)skb_push(skb
, 1) = size
+ 1;
834 if (!DIGITAL_DRV_CAPS_IN_CRC(ddev
))
835 digital_skb_add_crc_f(skb
);
837 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sensf_res
,
845 static void digital_in_recv_iso15693_inv_res(struct nfc_digital_dev
*ddev
,
846 void *arg
, struct sk_buff
*resp
)
848 struct digital_iso15693_inv_res
*res
;
849 struct nfc_target
*target
= NULL
;
858 if (resp
->len
!= sizeof(*res
)) {
863 res
= (struct digital_iso15693_inv_res
*)resp
->data
;
865 if (!DIGITAL_ISO15693_RES_IS_VALID(res
->flags
)) {
866 PROTOCOL_ERR("ISO15693 - 10.3.1");
871 target
= kzalloc(sizeof(*target
), GFP_KERNEL
);
877 target
->is_iso15693
= 1;
878 target
->iso15693_dsfid
= res
->dsfid
;
879 memcpy(target
->iso15693_uid
, &res
->uid
, sizeof(target
->iso15693_uid
));
881 rc
= digital_target_found(ddev
, target
, NFC_PROTO_ISO15693
);
889 digital_poll_next_tech(ddev
);
892 int digital_in_send_iso15693_inv_req(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
894 struct digital_iso15693_inv_req
*req
;
898 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
,
899 NFC_DIGITAL_RF_TECH_ISO15693
);
903 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
904 NFC_DIGITAL_FRAMING_ISO15693_INVENTORY
);
908 skb
= digital_skb_alloc(ddev
, sizeof(*req
));
912 skb_put(skb
, sizeof(*req
) - sizeof(req
->mask
)); /* No mask */
913 req
= (struct digital_iso15693_inv_req
*)skb
->data
;
915 /* Single sub-carrier, high data rate, no AFI, single slot
918 req
->flags
= DIGITAL_ISO15693_REQ_FLAG_DATA_RATE
|
919 DIGITAL_ISO15693_REQ_FLAG_INVENTORY
|
920 DIGITAL_ISO15693_REQ_FLAG_NB_SLOTS
;
921 req
->cmd
= DIGITAL_CMD_ISO15693_INVENTORY_REQ
;
924 rc
= digital_in_send_cmd(ddev
, skb
, 30,
925 digital_in_recv_iso15693_inv_res
, NULL
);
932 static int digital_tg_send_sel_res(struct nfc_digital_dev
*ddev
)
937 skb
= digital_skb_alloc(ddev
, 1);
941 skb_put_u8(skb
, DIGITAL_SEL_RES_NFC_DEP
);
943 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
))
944 digital_skb_add_crc_a(skb
);
946 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
947 NFC_DIGITAL_FRAMING_NFCA_ANTICOL_COMPLETE
);
953 rc
= digital_tg_send_cmd(ddev
, skb
, 300, digital_tg_recv_atr_req
,
961 static void digital_tg_recv_sel_req(struct nfc_digital_dev
*ddev
, void *arg
,
962 struct sk_buff
*resp
)
972 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
)) {
973 rc
= digital_skb_check_crc_a(resp
);
975 PROTOCOL_ERR("4.4.1.3");
980 /* Silently ignore SEL_REQ content and send a SEL_RES for NFC-DEP */
982 rc
= digital_tg_send_sel_res(ddev
);
986 digital_poll_next_tech(ddev
);
991 static int digital_tg_send_sdd_res(struct nfc_digital_dev
*ddev
)
994 struct digital_sdd_res
*sdd_res
;
997 skb
= digital_skb_alloc(ddev
, sizeof(struct digital_sdd_res
));
1001 skb_put(skb
, sizeof(struct digital_sdd_res
));
1002 sdd_res
= (struct digital_sdd_res
*)skb
->data
;
1004 sdd_res
->nfcid1
[0] = 0x08;
1005 get_random_bytes(sdd_res
->nfcid1
+ 1, 3);
1008 for (i
= 0; i
< 4; i
++)
1009 sdd_res
->bcc
^= sdd_res
->nfcid1
[i
];
1011 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
1012 NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A
);
1018 rc
= digital_tg_send_cmd(ddev
, skb
, 300, digital_tg_recv_sel_req
,
1026 static void digital_tg_recv_sdd_req(struct nfc_digital_dev
*ddev
, void *arg
,
1027 struct sk_buff
*resp
)
1038 sdd_req
= resp
->data
;
1040 if (resp
->len
< 2 || sdd_req
[0] != DIGITAL_CMD_SEL_REQ_CL1
||
1041 sdd_req
[1] != DIGITAL_SDD_REQ_SEL_PAR
) {
1046 rc
= digital_tg_send_sdd_res(ddev
);
1050 digital_poll_next_tech(ddev
);
1052 dev_kfree_skb(resp
);
1055 static int digital_tg_send_sens_res(struct nfc_digital_dev
*ddev
)
1057 struct sk_buff
*skb
;
1061 skb
= digital_skb_alloc(ddev
, 2);
1065 sens_res
= skb_put(skb
, 2);
1067 sens_res
[0] = (DIGITAL_SENS_RES_NFC_DEP
>> 8) & 0xFF;
1068 sens_res
[1] = DIGITAL_SENS_RES_NFC_DEP
& 0xFF;
1070 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
1071 NFC_DIGITAL_FRAMING_NFCA_STANDARD
);
1077 rc
= digital_tg_send_cmd(ddev
, skb
, 300, digital_tg_recv_sdd_req
,
1085 void digital_tg_recv_sens_req(struct nfc_digital_dev
*ddev
, void *arg
,
1086 struct sk_buff
*resp
)
1097 sens_req
= resp
->data
[0];
1099 if (!resp
->len
|| (sens_req
!= DIGITAL_CMD_SENS_REQ
&&
1100 sens_req
!= DIGITAL_CMD_ALL_REQ
)) {
1105 rc
= digital_tg_send_sens_res(ddev
);
1109 digital_poll_next_tech(ddev
);
1111 dev_kfree_skb(resp
);
1114 static void digital_tg_recv_atr_or_sensf_req(struct nfc_digital_dev
*ddev
,
1115 void *arg
, struct sk_buff
*resp
)
1117 if (!IS_ERR(resp
) && (resp
->len
>= 2) &&
1118 (resp
->data
[1] == DIGITAL_CMD_SENSF_REQ
))
1119 digital_tg_recv_sensf_req(ddev
, arg
, resp
);
1121 digital_tg_recv_atr_req(ddev
, arg
, resp
);
1126 static int digital_tg_send_sensf_res(struct nfc_digital_dev
*ddev
,
1127 struct digital_sensf_req
*sensf_req
)
1129 struct sk_buff
*skb
;
1132 struct digital_sensf_res
*sensf_res
;
1134 size
= sizeof(struct digital_sensf_res
);
1136 if (sensf_req
->rc
== DIGITAL_SENSF_REQ_RC_NONE
)
1137 size
-= sizeof(sensf_res
->rd
);
1139 skb
= digital_skb_alloc(ddev
, size
);
1145 sensf_res
= (struct digital_sensf_res
*)skb
->data
;
1147 memset(sensf_res
, 0, size
);
1149 sensf_res
->cmd
= DIGITAL_CMD_SENSF_RES
;
1150 sensf_res
->nfcid2
[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1
;
1151 sensf_res
->nfcid2
[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2
;
1152 get_random_bytes(&sensf_res
->nfcid2
[2], 6);
1154 switch (sensf_req
->rc
) {
1155 case DIGITAL_SENSF_REQ_RC_SC
:
1156 sensf_res
->rd
[0] = sensf_req
->sc1
;
1157 sensf_res
->rd
[1] = sensf_req
->sc2
;
1159 case DIGITAL_SENSF_REQ_RC_AP
:
1160 sensf_res
->rd
[0] = DIGITAL_SENSF_RES_RD_AP_B1
;
1161 sensf_res
->rd
[1] = DIGITAL_SENSF_RES_RD_AP_B2
;
1165 *(u8
*)skb_push(skb
, sizeof(u8
)) = size
+ 1;
1167 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
))
1168 digital_skb_add_crc_f(skb
);
1170 rc
= digital_tg_send_cmd(ddev
, skb
, 300,
1171 digital_tg_recv_atr_or_sensf_req
, NULL
);
1178 void digital_tg_recv_sensf_req(struct nfc_digital_dev
*ddev
, void *arg
,
1179 struct sk_buff
*resp
)
1181 struct digital_sensf_req
*sensf_req
;
1190 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
)) {
1191 rc
= digital_skb_check_crc_f(resp
);
1193 PROTOCOL_ERR("6.4.1.8");
1198 if (resp
->len
!= sizeof(struct digital_sensf_req
) + 1) {
1204 sensf_req
= (struct digital_sensf_req
*)resp
->data
;
1206 if (sensf_req
->cmd
!= DIGITAL_CMD_SENSF_REQ
) {
1211 rc
= digital_tg_send_sensf_res(ddev
, sensf_req
);
1215 digital_poll_next_tech(ddev
);
1217 dev_kfree_skb(resp
);
1220 static int digital_tg_config_nfca(struct nfc_digital_dev
*ddev
)
1224 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
,
1225 NFC_DIGITAL_RF_TECH_106A
);
1229 return digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
1230 NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
);
1233 int digital_tg_listen_nfca(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
1237 rc
= digital_tg_config_nfca(ddev
);
1241 return digital_tg_listen(ddev
, 300, digital_tg_recv_sens_req
, NULL
);
1244 static int digital_tg_config_nfcf(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
1248 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
, rf_tech
);
1252 return digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
1253 NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
);
1256 int digital_tg_listen_nfcf(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
1260 rc
= digital_tg_config_nfcf(ddev
, rf_tech
);
1264 return digital_tg_listen(ddev
, 300, digital_tg_recv_sensf_req
, NULL
);
1267 void digital_tg_recv_md_req(struct nfc_digital_dev
*ddev
, void *arg
,
1268 struct sk_buff
*resp
)
1278 rc
= ddev
->ops
->tg_get_rf_tech(ddev
, &rf_tech
);
1283 case NFC_DIGITAL_RF_TECH_106A
:
1284 rc
= digital_tg_config_nfca(ddev
);
1287 digital_tg_recv_sens_req(ddev
, arg
, resp
);
1289 case NFC_DIGITAL_RF_TECH_212F
:
1290 case NFC_DIGITAL_RF_TECH_424F
:
1291 rc
= digital_tg_config_nfcf(ddev
, rf_tech
);
1294 digital_tg_recv_sensf_req(ddev
, arg
, resp
);
1303 digital_poll_next_tech(ddev
);
1304 dev_kfree_skb(resp
);