20 #define pr_fmt(fmt) "hci: %s: " fmt, __func__
23 #include <linux/kernel.h>
24 #include <linux/module.h>
27 #include <net/nfc/nfc.h>
34 #define HCI_CMDS_HEADROOM 1
36 static int nfc_hci_result_to_errno(
u8 result)
59 if (timer_pending(&hdev->
cmd_timer) == 0) {
79 pr_debug(
"msg_tx_queue has a cmd to send\n");
108 static void nfc_hci_msg_rx_work(
struct work_struct *work)
130 static void __nfc_hci_cmd_completion(
struct nfc_hci_dev *hdev,
int err,
157 __nfc_hci_cmd_completion(hdev, nfc_hci_result_to_errno(result), skb);
169 static u32 nfc_hci_sak_to_protocol(
u8 sak)
185 static int nfc_hci_target_discovered(
struct nfc_hci_dev *hdev,
u8 gate)
211 if (atqa_skb->
len != 2 || sak_skb->
len != 1) {
217 nfc_hci_sak_to_protocol(sak_skb->
data[0]);
239 if (hdev->
ops->complete_target_discovered) {
240 r = hdev->
ops->complete_target_discovered(hdev, gate,
250 if (hdev->
ops->target_from_gate)
251 r = hdev->
ops->target_from_gate(hdev, gate, targets);
257 if (hdev->
ops->complete_target_discovered) {
258 r = hdev->
ops->complete_target_discovered(hdev, gate,
291 if (skb->
data[0] == 3) {
301 if (skb->
data[0] != 0) {
306 r = nfc_hci_target_discovered(hdev,
325 static void nfc_hci_cmd_timeout(
unsigned long data)
332 static int hci_dev_connect_gates(
struct nfc_hci_dev *hdev,
u8 gate_count,
336 while (gate_count--) {
347 static int hci_dev_session_init(
struct nfc_hci_dev *hdev)
385 r = hci_dev_connect_gates(hdev, hdev->
init_data.gate_count,
406 static int hci_dev_version(
struct nfc_hci_dev *hdev)
463 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
466 if (hdev->
ops->open) {
467 r = hdev->
ops->open(hdev);
476 r = hci_dev_session_init(hdev);
485 if (hdev->
ops->hci_ready) {
486 r = hdev->
ops->hci_ready(hdev);
491 r = hci_dev_version(hdev);
501 if (hdev->
ops->close)
502 hdev->
ops->close(hdev);
507 static int hci_dev_down(
struct nfc_dev *nfc_dev)
509 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
513 if (hdev->
ops->close)
514 hdev->
ops->close(hdev);
521 static int hci_start_poll(
struct nfc_dev *nfc_dev,
522 u32 im_protocols,
u32 tm_protocols)
524 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
526 if (hdev->
ops->start_poll)
527 return hdev->
ops->start_poll(hdev, im_protocols, tm_protocols);
533 static void hci_stop_poll(
struct nfc_dev *nfc_dev)
535 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
541 static int hci_activate_target(
struct nfc_dev *nfc_dev,
547 static void hci_deactivate_target(
struct nfc_dev *nfc_dev,
552 #define HCI_CB_TYPE_TRANSCEIVE 1
554 static void hci_transceive_cb(
void *
context,
struct sk_buff *skb,
int err)
577 static int hci_transceive(
struct nfc_dev *nfc_dev,
struct nfc_target *
target,
581 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
589 if (hdev->
ops->data_exchange) {
590 r = hdev->
ops->data_exchange(hdev, target, skb, cb,
604 skb->
len, hci_transceive_cb, hdev);
607 if (hdev->
ops->data_exchange) {
608 r = hdev->
ops->data_exchange(hdev, target, skb, cb,
623 static int hci_check_presence(
struct nfc_dev *nfc_dev,
626 struct nfc_hci_dev *hdev = nfc_get_drvdata(nfc_dev);
628 if (hdev->
ops->check_presence)
629 return hdev->
ops->check_presence(hdev, target);
634 static void nfc_hci_failure(
struct nfc_hci_dev *hdev,
int err)
643 __nfc_hci_cmd_completion(hdev, err,
NULL);
649 static void nfc_hci_llc_failure(
struct nfc_hci_dev *hdev,
int err)
651 nfc_hci_failure(hdev, err);
677 msg_len += (frag_skb->
len -
683 if (hcp_skb ==
NULL) {
684 nfc_hci_failure(hdev, -
ENOMEM);
721 static struct nfc_ops hci_nfc_ops = {
722 .dev_up = hci_dev_up,
723 .dev_down = hci_dev_down,
724 .start_poll = hci_start_poll,
725 .stop_poll = hci_stop_poll,
726 .activate_target = hci_activate_target,
727 .deactivate_target = hci_deactivate_target,
728 .im_transceive = hci_transceive,
729 .check_presence = hci_check_presence,
735 const char *llc_name,
738 int max_link_payload)
753 nfc_hci_recv_from_llc, tx_headroom,
754 tx_tailroom, nfc_hci_llc_failure);
773 nfc_set_drvdata(hdev->
ndev, hdev);
783 nfc_free_device(hdev->
ndev);
799 hdev->
cmd_timer.function = nfc_hci_cmd_timeout;
847 nfc_hci_failure(hdev, err);
857 static int __init nfc_hci_init(
void)
862 static void __exit nfc_hci_exit(
void)