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
31 #define DIGITAL_SEL_RES_NFCID1_COMPLETE(sel_res) (!((sel_res) & 0x04))
32 #define DIGITAL_SEL_RES_IS_T2T(sel_res) (!((sel_res) & 0x60))
33 #define DIGITAL_SEL_RES_IS_T4T(sel_res) ((sel_res) & 0x20)
34 #define DIGITAL_SEL_RES_IS_NFC_DEP(sel_res) ((sel_res) & 0x40)
36 #define DIGITAL_SENS_RES_IS_T1T(sens_res) (((sens_res) & 0x0C00) == 0x0C00)
37 #define DIGITAL_SENS_RES_IS_VALID(sens_res) \
38 ((!((sens_res) & 0x001F) && (((sens_res) & 0x0C00) == 0x0C00)) || \
39 (((sens_res) & 0x001F) && ((sens_res) & 0x0C00) != 0x0C00))
41 #define DIGITAL_MIFARE_READ_RES_LEN 16
42 #define DIGITAL_MIFARE_ACK_RES 0x0A
44 #define DIGITAL_CMD_SENSB_REQ 0x05
45 #define DIGITAL_SENSB_ADVANCED BIT(5)
46 #define DIGITAL_SENSB_EXTENDED BIT(4)
47 #define DIGITAL_SENSB_ALLB_REQ BIT(3)
48 #define DIGITAL_SENSB_N(n) ((n) & 0x7)
50 #define DIGITAL_CMD_SENSB_RES 0x50
52 #define DIGITAL_CMD_ATTRIB_REQ 0x1D
53 #define DIGITAL_ATTRIB_P1_TR0_DEFAULT (0x0 << 6)
54 #define DIGITAL_ATTRIB_P1_TR1_DEFAULT (0x0 << 4)
55 #define DIGITAL_ATTRIB_P1_SUPRESS_EOS BIT(3)
56 #define DIGITAL_ATTRIB_P1_SUPRESS_SOS BIT(2)
57 #define DIGITAL_ATTRIB_P2_LISTEN_POLL_1 (0x0 << 6)
58 #define DIGITAL_ATTRIB_P2_POLL_LISTEN_1 (0x0 << 4)
59 #define DIGITAL_ATTRIB_P2_MAX_FRAME_256 0x8
60 #define DIGITAL_ATTRIB_P4_DID(n) ((n) & 0xf)
62 #define DIGITAL_CMD_SENSF_REQ 0x00
63 #define DIGITAL_CMD_SENSF_RES 0x01
65 #define DIGITAL_SENSF_RES_MIN_LENGTH 17
66 #define DIGITAL_SENSF_RES_RD_AP_B1 0x00
67 #define DIGITAL_SENSF_RES_RD_AP_B2 0x8F
69 #define DIGITAL_SENSF_REQ_RC_NONE 0
70 #define DIGITAL_SENSF_REQ_RC_SC 1
71 #define DIGITAL_SENSF_REQ_RC_AP 2
73 #define DIGITAL_CMD_ISO15693_INVENTORY_REQ 0x01
75 #define DIGITAL_ISO15693_REQ_FLAG_DATA_RATE BIT(1)
76 #define DIGITAL_ISO15693_REQ_FLAG_INVENTORY BIT(2)
77 #define DIGITAL_ISO15693_REQ_FLAG_NB_SLOTS BIT(5)
78 #define DIGITAL_ISO15693_RES_FLAG_ERROR BIT(0)
79 #define DIGITAL_ISO15693_RES_IS_VALID(flags) \
80 (!((flags) & DIGITAL_ISO15693_RES_FLAG_ERROR))
82 #define DIGITAL_ISO_DEP_I_PCB 0x02
83 #define DIGITAL_ISO_DEP_PNI(pni) ((pni) & 0x01)
85 #define DIGITAL_ISO_DEP_PCB_TYPE(pcb) ((pcb) & 0xC0)
87 #define DIGITAL_ISO_DEP_I_BLOCK 0x00
89 #define DIGITAL_ISO_DEP_BLOCK_HAS_DID(pcb) ((pcb) & 0x08)
91 static const u8 digital_ats_fsc
[] = {
92 16, 24, 32, 40, 48, 64, 96, 128,
95 #define DIGITAL_ATS_FSCI(t0) ((t0) & 0x0F)
96 #define DIGITAL_SENSB_FSCI(pi2) (((pi2) & 0xF0) >> 4)
97 #define DIGITAL_ATS_MAX_FSC 256
99 #define DIGITAL_RATS_BYTE1 0xE0
100 #define DIGITAL_RATS_PARAM 0x80
102 struct digital_sdd_res
{
107 struct digital_sel_req
{
114 struct digital_sensb_req
{
120 struct digital_sensb_res
{
127 struct digital_attrib_req
{
136 struct digital_attrib_res
{
140 struct digital_sensf_req
{
148 struct digital_sensf_res
{
159 struct digital_iso15693_inv_req
{
166 struct digital_iso15693_inv_res
{
172 static int digital_in_send_sdd_req(struct nfc_digital_dev
*ddev
,
173 struct nfc_target
*target
);
175 int digital_in_iso_dep_pull_sod(struct nfc_digital_dev
*ddev
,
185 block_type
= DIGITAL_ISO_DEP_PCB_TYPE(pcb
);
187 /* No support fo R-block nor S-block */
188 if (block_type
!= DIGITAL_ISO_DEP_I_BLOCK
) {
189 pr_err("ISO_DEP R-block and S-block not supported\n");
193 if (DIGITAL_ISO_DEP_BLOCK_HAS_DID(pcb
)) {
194 pr_err("DID field in ISO_DEP PCB not supported\n");
203 int digital_in_iso_dep_push_sod(struct nfc_digital_dev
*ddev
,
207 * Chaining not supported so skb->len + 1 PCB byte + 2 CRC bytes must
208 * not be greater than remote FSC
210 if (skb
->len
+ 3 > ddev
->target_fsc
)
215 *skb
->data
= DIGITAL_ISO_DEP_I_PCB
| ddev
->curr_nfc_dep_pni
;
217 ddev
->curr_nfc_dep_pni
=
218 DIGITAL_ISO_DEP_PNI(ddev
->curr_nfc_dep_pni
+ 1);
223 static void digital_in_recv_ats(struct nfc_digital_dev
*ddev
, void *arg
,
224 struct sk_buff
*resp
)
226 struct nfc_target
*target
= arg
;
241 fsdi
= DIGITAL_ATS_FSCI(resp
->data
[1]);
243 ddev
->target_fsc
= DIGITAL_ATS_MAX_FSC
;
245 ddev
->target_fsc
= digital_ats_fsc
[fsdi
];
247 ddev
->curr_nfc_dep_pni
= 0;
249 rc
= digital_target_found(ddev
, target
, NFC_PROTO_ISO14443
);
256 digital_poll_next_tech(ddev
);
259 static int digital_in_send_rats(struct nfc_digital_dev
*ddev
,
260 struct nfc_target
*target
)
265 skb
= digital_skb_alloc(ddev
, 2);
269 *skb_put(skb
, 1) = DIGITAL_RATS_BYTE1
;
270 *skb_put(skb
, 1) = DIGITAL_RATS_PARAM
;
272 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_ats
,
280 static void digital_in_recv_sel_res(struct nfc_digital_dev
*ddev
, void *arg
,
281 struct sk_buff
*resp
)
283 struct nfc_target
*target
= arg
;
294 if (!DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
295 rc
= digital_skb_check_crc_a(resp
);
297 PROTOCOL_ERR("4.4.1.3");
307 sel_res
= resp
->data
[0];
309 if (!DIGITAL_SEL_RES_NFCID1_COMPLETE(sel_res
)) {
310 rc
= digital_in_send_sdd_req(ddev
, target
);
317 target
->sel_res
= sel_res
;
319 if (DIGITAL_SEL_RES_IS_T2T(sel_res
)) {
320 nfc_proto
= NFC_PROTO_MIFARE
;
321 } else if (DIGITAL_SEL_RES_IS_T4T(sel_res
)) {
322 rc
= digital_in_send_rats(ddev
, target
);
326 * Skip target_found and don't free it for now. This will be
327 * done when receiving the ATS
330 } else if (DIGITAL_SEL_RES_IS_NFC_DEP(sel_res
)) {
331 nfc_proto
= NFC_PROTO_NFC_DEP
;
337 rc
= digital_target_found(ddev
, target
, nfc_proto
);
346 digital_poll_next_tech(ddev
);
349 static int digital_in_send_sel_req(struct nfc_digital_dev
*ddev
,
350 struct nfc_target
*target
,
351 struct digital_sdd_res
*sdd_res
)
354 struct digital_sel_req
*sel_req
;
358 skb
= digital_skb_alloc(ddev
, sizeof(struct digital_sel_req
));
362 skb_put(skb
, sizeof(struct digital_sel_req
));
363 sel_req
= (struct digital_sel_req
*)skb
->data
;
365 if (target
->nfcid1_len
<= 4)
366 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL1
;
367 else if (target
->nfcid1_len
< 10)
368 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL2
;
370 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL3
;
372 sel_req
->sel_cmd
= sel_cmd
;
374 memcpy(sel_req
->nfcid1
, sdd_res
->nfcid1
, 4);
375 sel_req
->bcc
= sdd_res
->bcc
;
377 if (DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
378 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
379 NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A
);
383 digital_skb_add_crc_a(skb
);
386 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sel_res
,
395 static void digital_in_recv_sdd_res(struct nfc_digital_dev
*ddev
, void *arg
,
396 struct sk_buff
*resp
)
398 struct nfc_target
*target
= arg
;
399 struct digital_sdd_res
*sdd_res
;
410 if (resp
->len
< DIGITAL_SDD_RES_LEN
) {
411 PROTOCOL_ERR("4.7.2.8");
416 sdd_res
= (struct digital_sdd_res
*)resp
->data
;
418 for (i
= 0, bcc
= 0; i
< 4; i
++)
419 bcc
^= sdd_res
->nfcid1
[i
];
421 if (bcc
!= sdd_res
->bcc
) {
422 PROTOCOL_ERR("4.7.2.6");
427 if (sdd_res
->nfcid1
[0] == DIGITAL_SDD_RES_CT
) {
435 memcpy(target
->nfcid1
+ target
->nfcid1_len
, sdd_res
->nfcid1
+ offset
,
437 target
->nfcid1_len
+= size
;
439 rc
= digital_in_send_sel_req(ddev
, target
, sdd_res
);
446 digital_poll_next_tech(ddev
);
450 static int digital_in_send_sdd_req(struct nfc_digital_dev
*ddev
,
451 struct nfc_target
*target
)
457 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
458 NFC_DIGITAL_FRAMING_NFCA_STANDARD
);
462 skb
= digital_skb_alloc(ddev
, 2);
466 if (target
->nfcid1_len
== 0)
467 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL1
;
468 else if (target
->nfcid1_len
== 3)
469 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL2
;
471 sel_cmd
= DIGITAL_CMD_SEL_REQ_CL3
;
473 *skb_put(skb
, sizeof(u8
)) = sel_cmd
;
474 *skb_put(skb
, sizeof(u8
)) = DIGITAL_SDD_REQ_SEL_PAR
;
476 return digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sdd_res
,
480 static void digital_in_recv_sens_res(struct nfc_digital_dev
*ddev
, void *arg
,
481 struct sk_buff
*resp
)
483 struct nfc_target
*target
= NULL
;
492 if (resp
->len
< sizeof(u16
)) {
497 target
= kzalloc(sizeof(struct nfc_target
), GFP_KERNEL
);
503 target
->sens_res
= __le16_to_cpu(*(__le16
*)resp
->data
);
505 if (!DIGITAL_SENS_RES_IS_VALID(target
->sens_res
)) {
506 PROTOCOL_ERR("4.6.3.3");
511 if (DIGITAL_SENS_RES_IS_T1T(target
->sens_res
))
512 rc
= digital_target_found(ddev
, target
, NFC_PROTO_JEWEL
);
514 rc
= digital_in_send_sdd_req(ddev
, target
);
521 digital_poll_next_tech(ddev
);
525 int digital_in_send_sens_req(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
530 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
,
531 NFC_DIGITAL_RF_TECH_106A
);
535 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
536 NFC_DIGITAL_FRAMING_NFCA_SHORT
);
540 skb
= digital_skb_alloc(ddev
, 1);
544 *skb_put(skb
, sizeof(u8
)) = DIGITAL_CMD_SENS_REQ
;
546 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sens_res
, NULL
);
553 int digital_in_recv_mifare_res(struct sk_buff
*resp
)
555 /* Successful READ command response is 16 data bytes + 2 CRC bytes long.
556 * Since the driver can't differentiate a ACK/NACK response from a valid
557 * READ response, the CRC calculation must be handled at digital level
558 * even if the driver supports it for this technology.
560 if (resp
->len
== DIGITAL_MIFARE_READ_RES_LEN
+ DIGITAL_CRC_LEN
) {
561 if (digital_skb_check_crc_a(resp
)) {
562 PROTOCOL_ERR("9.4.1.2");
569 /* ACK response (i.e. successful WRITE). */
570 if (resp
->len
== 1 && resp
->data
[0] == DIGITAL_MIFARE_ACK_RES
) {
575 /* NACK and any other responses are treated as error. */
579 static void digital_in_recv_attrib_res(struct nfc_digital_dev
*ddev
, void *arg
,
580 struct sk_buff
*resp
)
582 struct nfc_target
*target
= arg
;
583 struct digital_attrib_res
*attrib_res
;
592 if (resp
->len
< sizeof(*attrib_res
)) {
593 PROTOCOL_ERR("12.6.2");
598 attrib_res
= (struct digital_attrib_res
*)resp
->data
;
600 if (attrib_res
->mbli_did
& 0x0f) {
601 PROTOCOL_ERR("12.6.2.1");
606 rc
= digital_target_found(ddev
, target
, NFC_PROTO_ISO14443_B
);
613 digital_poll_next_tech(ddev
);
616 static int digital_in_send_attrib_req(struct nfc_digital_dev
*ddev
,
617 struct nfc_target
*target
,
618 struct digital_sensb_res
*sensb_res
)
620 struct digital_attrib_req
*attrib_req
;
624 skb
= digital_skb_alloc(ddev
, sizeof(*attrib_req
));
628 attrib_req
= (struct digital_attrib_req
*)skb_put(skb
,
629 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
= (struct digital_sensb_req
*)skb_put(skb
,
736 sensb_req
->cmd
= DIGITAL_CMD_SENSB_REQ
;
737 sensb_req
->afi
= 0x00; /* All families and sub-families */
738 sensb_req
->param
= DIGITAL_SENSB_N(0);
740 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sensb_res
,
748 static void digital_in_recv_sensf_res(struct nfc_digital_dev
*ddev
, void *arg
,
749 struct sk_buff
*resp
)
753 struct nfc_target target
;
754 struct digital_sensf_res
*sensf_res
;
762 if (resp
->len
< DIGITAL_SENSF_RES_MIN_LENGTH
) {
767 if (!DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
768 rc
= digital_skb_check_crc_f(resp
);
770 PROTOCOL_ERR("6.4.1.8");
777 memset(&target
, 0, sizeof(struct nfc_target
));
779 sensf_res
= (struct digital_sensf_res
*)resp
->data
;
781 memcpy(target
.sensf_res
, sensf_res
, resp
->len
);
782 target
.sensf_res_len
= resp
->len
;
784 memcpy(target
.nfcid2
, sensf_res
->nfcid2
, NFC_NFCID2_MAXSIZE
);
785 target
.nfcid2_len
= NFC_NFCID2_MAXSIZE
;
787 if (target
.nfcid2
[0] == DIGITAL_SENSF_NFCID2_NFC_DEP_B1
&&
788 target
.nfcid2
[1] == DIGITAL_SENSF_NFCID2_NFC_DEP_B2
)
789 proto
= NFC_PROTO_NFC_DEP
;
791 proto
= NFC_PROTO_FELICA
;
793 rc
= digital_target_found(ddev
, &target
, proto
);
799 digital_poll_next_tech(ddev
);
802 int digital_in_send_sensf_req(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
804 struct digital_sensf_req
*sensf_req
;
809 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
, rf_tech
);
813 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
814 NFC_DIGITAL_FRAMING_NFCF
);
818 size
= sizeof(struct digital_sensf_req
);
820 skb
= digital_skb_alloc(ddev
, size
);
826 sensf_req
= (struct digital_sensf_req
*)skb
->data
;
827 sensf_req
->cmd
= DIGITAL_CMD_SENSF_REQ
;
828 sensf_req
->sc1
= 0xFF;
829 sensf_req
->sc2
= 0xFF;
833 *skb_push(skb
, 1) = size
+ 1;
835 if (!DIGITAL_DRV_CAPS_IN_CRC(ddev
))
836 digital_skb_add_crc_f(skb
);
838 rc
= digital_in_send_cmd(ddev
, skb
, 30, digital_in_recv_sensf_res
,
846 static void digital_in_recv_iso15693_inv_res(struct nfc_digital_dev
*ddev
,
847 void *arg
, struct sk_buff
*resp
)
849 struct digital_iso15693_inv_res
*res
;
850 struct nfc_target
*target
= NULL
;
859 if (resp
->len
!= sizeof(*res
)) {
864 res
= (struct digital_iso15693_inv_res
*)resp
->data
;
866 if (!DIGITAL_ISO15693_RES_IS_VALID(res
->flags
)) {
867 PROTOCOL_ERR("ISO15693 - 10.3.1");
872 target
= kzalloc(sizeof(*target
), GFP_KERNEL
);
878 target
->is_iso15693
= 1;
879 target
->iso15693_dsfid
= res
->dsfid
;
880 memcpy(target
->iso15693_uid
, &res
->uid
, sizeof(target
->iso15693_uid
));
882 rc
= digital_target_found(ddev
, target
, NFC_PROTO_ISO15693
);
890 digital_poll_next_tech(ddev
);
893 int digital_in_send_iso15693_inv_req(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
895 struct digital_iso15693_inv_req
*req
;
899 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
,
900 NFC_DIGITAL_RF_TECH_ISO15693
);
904 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
905 NFC_DIGITAL_FRAMING_ISO15693_INVENTORY
);
909 skb
= digital_skb_alloc(ddev
, sizeof(*req
));
913 skb_put(skb
, sizeof(*req
) - sizeof(req
->mask
)); /* No mask */
914 req
= (struct digital_iso15693_inv_req
*)skb
->data
;
916 /* Single sub-carrier, high data rate, no AFI, single slot
919 req
->flags
= DIGITAL_ISO15693_REQ_FLAG_DATA_RATE
|
920 DIGITAL_ISO15693_REQ_FLAG_INVENTORY
|
921 DIGITAL_ISO15693_REQ_FLAG_NB_SLOTS
;
922 req
->cmd
= DIGITAL_CMD_ISO15693_INVENTORY_REQ
;
925 rc
= digital_in_send_cmd(ddev
, skb
, 30,
926 digital_in_recv_iso15693_inv_res
, NULL
);
933 static int digital_tg_send_sel_res(struct nfc_digital_dev
*ddev
)
938 skb
= digital_skb_alloc(ddev
, 1);
942 *skb_put(skb
, 1) = DIGITAL_SEL_RES_NFC_DEP
;
944 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
))
945 digital_skb_add_crc_a(skb
);
947 rc
= digital_tg_send_cmd(ddev
, skb
, 300, digital_tg_recv_atr_req
,
955 static void digital_tg_recv_sel_req(struct nfc_digital_dev
*ddev
, void *arg
,
956 struct sk_buff
*resp
)
966 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
)) {
967 rc
= digital_skb_check_crc_a(resp
);
969 PROTOCOL_ERR("4.4.1.3");
974 /* Silently ignore SEL_REQ content and send a SEL_RES for NFC-DEP */
976 rc
= digital_tg_send_sel_res(ddev
);
980 digital_poll_next_tech(ddev
);
985 static int digital_tg_send_sdd_res(struct nfc_digital_dev
*ddev
)
988 struct digital_sdd_res
*sdd_res
;
991 skb
= digital_skb_alloc(ddev
, sizeof(struct digital_sdd_res
));
995 skb_put(skb
, sizeof(struct digital_sdd_res
));
996 sdd_res
= (struct digital_sdd_res
*)skb
->data
;
998 sdd_res
->nfcid1
[0] = 0x08;
999 get_random_bytes(sdd_res
->nfcid1
+ 1, 3);
1002 for (i
= 0; i
< 4; i
++)
1003 sdd_res
->bcc
^= sdd_res
->nfcid1
[i
];
1005 rc
= digital_tg_send_cmd(ddev
, skb
, 300, digital_tg_recv_sel_req
,
1013 static void digital_tg_recv_sdd_req(struct nfc_digital_dev
*ddev
, void *arg
,
1014 struct sk_buff
*resp
)
1025 sdd_req
= resp
->data
;
1027 if (resp
->len
< 2 || sdd_req
[0] != DIGITAL_CMD_SEL_REQ_CL1
||
1028 sdd_req
[1] != DIGITAL_SDD_REQ_SEL_PAR
) {
1033 rc
= digital_tg_send_sdd_res(ddev
);
1037 digital_poll_next_tech(ddev
);
1039 dev_kfree_skb(resp
);
1042 static int digital_tg_send_sens_res(struct nfc_digital_dev
*ddev
)
1044 struct sk_buff
*skb
;
1048 skb
= digital_skb_alloc(ddev
, 2);
1052 sens_res
= skb_put(skb
, 2);
1054 sens_res
[0] = (DIGITAL_SENS_RES_NFC_DEP
>> 8) & 0xFF;
1055 sens_res
[1] = DIGITAL_SENS_RES_NFC_DEP
& 0xFF;
1057 rc
= digital_tg_send_cmd(ddev
, skb
, 300, digital_tg_recv_sdd_req
,
1065 void digital_tg_recv_sens_req(struct nfc_digital_dev
*ddev
, void *arg
,
1066 struct sk_buff
*resp
)
1077 sens_req
= resp
->data
[0];
1079 if (!resp
->len
|| (sens_req
!= DIGITAL_CMD_SENS_REQ
&&
1080 sens_req
!= DIGITAL_CMD_ALL_REQ
)) {
1085 rc
= digital_tg_send_sens_res(ddev
);
1089 digital_poll_next_tech(ddev
);
1091 dev_kfree_skb(resp
);
1094 static void digital_tg_recv_atr_or_sensf_req(struct nfc_digital_dev
*ddev
,
1095 void *arg
, struct sk_buff
*resp
)
1097 if (!IS_ERR(resp
) && (resp
->len
>= 2) &&
1098 (resp
->data
[1] == DIGITAL_CMD_SENSF_REQ
))
1099 digital_tg_recv_sensf_req(ddev
, arg
, resp
);
1101 digital_tg_recv_atr_req(ddev
, arg
, resp
);
1106 static int digital_tg_send_sensf_res(struct nfc_digital_dev
*ddev
,
1107 struct digital_sensf_req
*sensf_req
)
1109 struct sk_buff
*skb
;
1112 struct digital_sensf_res
*sensf_res
;
1114 size
= sizeof(struct digital_sensf_res
);
1116 if (sensf_req
->rc
== DIGITAL_SENSF_REQ_RC_NONE
)
1117 size
-= sizeof(sensf_res
->rd
);
1119 skb
= digital_skb_alloc(ddev
, size
);
1125 sensf_res
= (struct digital_sensf_res
*)skb
->data
;
1127 memset(sensf_res
, 0, size
);
1129 sensf_res
->cmd
= DIGITAL_CMD_SENSF_RES
;
1130 sensf_res
->nfcid2
[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1
;
1131 sensf_res
->nfcid2
[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2
;
1132 get_random_bytes(&sensf_res
->nfcid2
[2], 6);
1134 switch (sensf_req
->rc
) {
1135 case DIGITAL_SENSF_REQ_RC_SC
:
1136 sensf_res
->rd
[0] = sensf_req
->sc1
;
1137 sensf_res
->rd
[1] = sensf_req
->sc2
;
1139 case DIGITAL_SENSF_REQ_RC_AP
:
1140 sensf_res
->rd
[0] = DIGITAL_SENSF_RES_RD_AP_B1
;
1141 sensf_res
->rd
[1] = DIGITAL_SENSF_RES_RD_AP_B2
;
1145 *skb_push(skb
, sizeof(u8
)) = size
+ 1;
1147 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
))
1148 digital_skb_add_crc_f(skb
);
1150 rc
= digital_tg_send_cmd(ddev
, skb
, 300,
1151 digital_tg_recv_atr_or_sensf_req
, NULL
);
1158 void digital_tg_recv_sensf_req(struct nfc_digital_dev
*ddev
, void *arg
,
1159 struct sk_buff
*resp
)
1161 struct digital_sensf_req
*sensf_req
;
1170 if (!DIGITAL_DRV_CAPS_TG_CRC(ddev
)) {
1171 rc
= digital_skb_check_crc_f(resp
);
1173 PROTOCOL_ERR("6.4.1.8");
1178 if (resp
->len
!= sizeof(struct digital_sensf_req
) + 1) {
1184 sensf_req
= (struct digital_sensf_req
*)resp
->data
;
1186 if (sensf_req
->cmd
!= DIGITAL_CMD_SENSF_REQ
) {
1191 rc
= digital_tg_send_sensf_res(ddev
, sensf_req
);
1195 digital_poll_next_tech(ddev
);
1197 dev_kfree_skb(resp
);
1200 int digital_tg_listen_nfca(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
1204 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
, rf_tech
);
1208 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
1209 NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
);
1213 return digital_tg_listen(ddev
, 300, digital_tg_recv_sens_req
, NULL
);
1216 int digital_tg_listen_nfcf(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
1221 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_RF_TECH
, rf_tech
);
1225 rc
= digital_tg_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
,
1226 NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
);
1230 nfcid2
= kzalloc(NFC_NFCID2_MAXSIZE
, GFP_KERNEL
);
1234 nfcid2
[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1
;
1235 nfcid2
[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2
;
1236 get_random_bytes(nfcid2
+ 2, NFC_NFCID2_MAXSIZE
- 2);
1238 return digital_tg_listen(ddev
, 300, digital_tg_recv_sensf_req
, nfcid2
);