Skip to content

Commit 767f19a

Browse files
Ilan EliasSamuel Ortiz
authored andcommitted
NFC: Implement NCI dep_link_up and dep_link_down
During NFC-DEP target activation, store the remote general bytes to be used later in dep_link_up. When dep_link_up is called, activate the NFC-DEP target, and forward the remote general bytes. When dep_link_down is called, deactivate the target. Signed-off-by: Ilan Elias <ilane@ti.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
1 parent ac20683 commit 767f19a

4 files changed

Lines changed: 60 additions & 1 deletion

File tree

‎include/net/nfc/nci_core.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ struct nci_dev {
138138
data_exchange_cb_t data_exchange_cb;
139139
void *data_exchange_cb_context;
140140
struct sk_buff *rx_data_reassembly;
141+
142+
/* stored during intf_activated_ntf */
143+
__u8 remote_gb[NFC_MAX_GT_LEN];
144+
__u8 remote_gb_len;
141145
};
142146

143147
/* ----- NCI Devices ----- */

‎include/net/nfc/nfc.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ struct nfc_ops {
7272

7373
#define NFC_TARGET_IDX_ANY -1
7474
#define NFC_MAX_GT_LEN 48
75+
#define NFC_ATR_RES_GT_OFFSET 15
7576

7677
struct nfc_target {
7778
u32 idx;

‎net/nfc/nci/core.c‎

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
564564
{
565565
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
566566

567-
pr_debug("target_idx %d\n", target->idx);
567+
pr_debug("entry\n");
568568

569569
if (!ndev->target_active_prot) {
570570
pr_err("unable to deactivate target, no active target\n");
@@ -579,6 +579,38 @@ static void nci_deactivate_target(struct nfc_dev *nfc_dev,
579579
}
580580
}
581581

582+
583+
static int nci_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target,
584+
__u8 comm_mode, __u8 *gb, size_t gb_len)
585+
{
586+
struct nci_dev *ndev = nfc_get_drvdata(nfc_dev);
587+
int rc;
588+
589+
pr_debug("target_idx %d, comm_mode %d\n", target->idx, comm_mode);
590+
591+
rc = nci_activate_target(nfc_dev, target, NFC_PROTO_NFC_DEP);
592+
if (rc)
593+
return rc;
594+
595+
rc = nfc_set_remote_general_bytes(nfc_dev, ndev->remote_gb,
596+
ndev->remote_gb_len);
597+
if (!rc)
598+
rc = nfc_dep_link_is_up(nfc_dev, target->idx, NFC_COMM_PASSIVE,
599+
NFC_RF_INITIATOR);
600+
601+
return rc;
602+
}
603+
604+
static int nci_dep_link_down(struct nfc_dev *nfc_dev)
605+
{
606+
pr_debug("entry\n");
607+
608+
nci_deactivate_target(nfc_dev, NULL);
609+
610+
return 0;
611+
}
612+
613+
582614
static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target,
583615
struct sk_buff *skb,
584616
data_exchange_cb_t cb, void *cb_context)
@@ -612,6 +644,8 @@ static struct nfc_ops nci_nfc_ops = {
612644
.dev_down = nci_dev_down,
613645
.start_poll = nci_start_poll,
614646
.stop_poll = nci_stop_poll,
647+
.dep_link_up = nci_dep_link_up,
648+
.dep_link_down = nci_dep_link_down,
615649
.activate_target = nci_activate_target,
616650
.deactivate_target = nci_deactivate_target,
617651
.im_transceive = nci_transceive,

‎net/nfc/nci/ntf.c‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ static int nci_add_new_protocol(struct nci_dev *ndev,
176176
protocol = NFC_PROTO_ISO14443_B_MASK;
177177
else if (rf_protocol == NCI_RF_PROTOCOL_T3T)
178178
protocol = NFC_PROTO_FELICA_MASK;
179+
else if (rf_protocol == NCI_RF_PROTOCOL_NFC_DEP)
180+
protocol = NFC_PROTO_NFC_DEP_MASK;
179181
else
180182
protocol = 0;
181183

@@ -505,6 +507,24 @@ static void nci_rf_intf_activated_ntf_packet(struct nci_dev *ndev,
505507

506508
/* set the available credits to initial value */
507509
atomic_set(&ndev->credits_cnt, ndev->initial_num_credits);
510+
511+
/* store general bytes to be reported later in dep_link_up */
512+
if (ntf.rf_interface == NCI_RF_INTERFACE_NFC_DEP) {
513+
ndev->remote_gb_len = 0;
514+
515+
if (ntf.activation_params_len > 0) {
516+
/* ATR_RES general bytes at offset 15 */
517+
ndev->remote_gb_len = min_t(__u8,
518+
(ntf.activation_params
519+
.poll_nfc_dep.atr_res_len
520+
- NFC_ATR_RES_GT_OFFSET),
521+
NFC_MAX_GT_LEN);
522+
memcpy(ndev->remote_gb,
523+
(ntf.activation_params.poll_nfc_dep
524+
.atr_res + NFC_ATR_RES_GT_OFFSET),
525+
ndev->remote_gb_len);
526+
}
527+
}
508528
}
509529

510530
if (atomic_read(&ndev->state) == NCI_DISCOVERY) {

0 commit comments

Comments
 (0)