Commit 767f19ae698e535f308663c48245fa951abebe20
Committed by
Samuel Ortiz
1 parent
ac20683840
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
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>
Showing 4 changed files with 60 additions and 1 deletions Side-by-side Diff
include/net/nfc/nci_core.h
... | ... | @@ -138,6 +138,10 @@ |
138 | 138 | data_exchange_cb_t data_exchange_cb; |
139 | 139 | void *data_exchange_cb_context; |
140 | 140 | 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; | |
141 | 145 | }; |
142 | 146 | |
143 | 147 | /* ----- NCI Devices ----- */ |
include/net/nfc/nfc.h
net/nfc/nci/core.c
... | ... | @@ -564,7 +564,7 @@ |
564 | 564 | { |
565 | 565 | struct nci_dev *ndev = nfc_get_drvdata(nfc_dev); |
566 | 566 | |
567 | - pr_debug("target_idx %d\n", target->idx); | |
567 | + pr_debug("entry\n"); | |
568 | 568 | |
569 | 569 | if (!ndev->target_active_prot) { |
570 | 570 | pr_err("unable to deactivate target, no active target\n"); |
... | ... | @@ -579,6 +579,38 @@ |
579 | 579 | } |
580 | 580 | } |
581 | 581 | |
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 | + | |
582 | 614 | static int nci_transceive(struct nfc_dev *nfc_dev, struct nfc_target *target, |
583 | 615 | struct sk_buff *skb, |
584 | 616 | data_exchange_cb_t cb, void *cb_context) |
... | ... | @@ -612,6 +644,8 @@ |
612 | 644 | .dev_down = nci_dev_down, |
613 | 645 | .start_poll = nci_start_poll, |
614 | 646 | .stop_poll = nci_stop_poll, |
647 | + .dep_link_up = nci_dep_link_up, | |
648 | + .dep_link_down = nci_dep_link_down, | |
615 | 649 | .activate_target = nci_activate_target, |
616 | 650 | .deactivate_target = nci_deactivate_target, |
617 | 651 | .im_transceive = nci_transceive, |
net/nfc/nci/ntf.c
... | ... | @@ -176,6 +176,8 @@ |
176 | 176 | protocol = NFC_PROTO_ISO14443_B_MASK; |
177 | 177 | else if (rf_protocol == NCI_RF_PROTOCOL_T3T) |
178 | 178 | protocol = NFC_PROTO_FELICA_MASK; |
179 | + else if (rf_protocol == NCI_RF_PROTOCOL_NFC_DEP) | |
180 | + protocol = NFC_PROTO_NFC_DEP_MASK; | |
179 | 181 | else |
180 | 182 | protocol = 0; |
181 | 183 | |
... | ... | @@ -505,6 +507,24 @@ |
505 | 507 | |
506 | 508 | /* set the available credits to initial value */ |
507 | 509 | 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 | + } | |
508 | 528 | } |
509 | 529 | |
510 | 530 | if (atomic_read(&ndev->state) == NCI_DISCOVERY) { |