pn544.c (3943826177945c0f7e82fcf1f37797149c6d9c91) | pn544.c (17936b43f0fdede23582d83a45622751409c99b9) |
---|---|
1/* 2 * HCI based Driver for NXP PN544 NFC Chip 3 * 4 * Copyright (C) 2012 Intel Corporation. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. --- 4 unchanged lines hidden (view full) --- 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the 17 * Free Software Foundation, Inc., 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 | 1/* 2 * HCI based Driver for NXP PN544 NFC Chip 3 * 4 * Copyright (C) 2012 Intel Corporation. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify it 7 * under the terms and conditions of the GNU General Public License, 8 * version 2, as published by the Free Software Foundation. --- 4 unchanged lines hidden (view full) --- 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the 17 * Free Software Foundation, Inc., 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 */ 20 |
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 22 |
|
21#include <linux/delay.h> 22#include <linux/slab.h> 23#include <linux/module.h> 24 25#include <linux/nfc.h> 26#include <net/nfc/hci.h> 27#include <net/nfc/llc.h> 28 --- 357 unchanged lines hidden (view full) --- 386 r = nfc_hci_set_param(hdev, PN544_POLLING_LOOP_MGMT_GATE, 387 PN544_PL_RDPHASES, &phases, 1); 388 if (r < 0) 389 return r; 390 391 if ((im_protocols | tm_protocols) & NFC_PROTO_NFC_DEP_MASK) { 392 hdev->gb = nfc_get_local_general_bytes(hdev->ndev, 393 &hdev->gb_len); | 23#include <linux/delay.h> 24#include <linux/slab.h> 25#include <linux/module.h> 26 27#include <linux/nfc.h> 28#include <net/nfc/hci.h> 29#include <net/nfc/llc.h> 30 --- 357 unchanged lines hidden (view full) --- 388 r = nfc_hci_set_param(hdev, PN544_POLLING_LOOP_MGMT_GATE, 389 PN544_PL_RDPHASES, &phases, 1); 390 if (r < 0) 391 return r; 392 393 if ((im_protocols | tm_protocols) & NFC_PROTO_NFC_DEP_MASK) { 394 hdev->gb = nfc_get_local_general_bytes(hdev->ndev, 395 &hdev->gb_len); |
394 pr_debug("generate local bytes %p", hdev->gb); | 396 pr_debug("generate local bytes %p\n", hdev->gb); |
395 if (hdev->gb == NULL || hdev->gb_len == 0) { 396 im_protocols &= ~NFC_PROTO_NFC_DEP_MASK; 397 tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK; 398 } 399 } 400 401 if (im_protocols & NFC_PROTO_NFC_DEP_MASK) { 402 r = nfc_hci_send_event(hdev, --- 285 unchanged lines hidden (view full) --- 688 kfree_skb(skb); 689 690 return r; 691} 692 693static int pn544_hci_check_presence(struct nfc_hci_dev *hdev, 694 struct nfc_target *target) 695{ | 397 if (hdev->gb == NULL || hdev->gb_len == 0) { 398 im_protocols &= ~NFC_PROTO_NFC_DEP_MASK; 399 tm_protocols &= ~NFC_PROTO_NFC_DEP_MASK; 400 } 401 } 402 403 if (im_protocols & NFC_PROTO_NFC_DEP_MASK) { 404 r = nfc_hci_send_event(hdev, --- 285 unchanged lines hidden (view full) --- 690 kfree_skb(skb); 691 692 return r; 693} 694 695static int pn544_hci_check_presence(struct nfc_hci_dev *hdev, 696 struct nfc_target *target) 697{ |
696 pr_debug("supported protocol %d", target->supported_protocols); | 698 pr_debug("supported protocol %d\b", target->supported_protocols); |
697 if (target->supported_protocols & (NFC_PROTO_ISO14443_MASK | 698 NFC_PROTO_ISO14443_B_MASK)) { 699 return nfc_hci_send_cmd(hdev, target->hci_reader_gate, 700 PN544_RF_READER_CMD_PRESENCE_CHECK, 701 NULL, 0, NULL); 702 } else if (target->supported_protocols & NFC_PROTO_MIFARE_MASK) { 703 if (target->nfcid1_len != 4 && target->nfcid1_len != 7 && 704 target->nfcid1_len != 10) --- 20 unchanged lines hidden (view full) --- 725 * 1: driver does not handle the event, please do standard processing 726 */ 727static int pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 gate, u8 event, 728 struct sk_buff *skb) 729{ 730 struct sk_buff *rgb_skb = NULL; 731 int r; 732 | 699 if (target->supported_protocols & (NFC_PROTO_ISO14443_MASK | 700 NFC_PROTO_ISO14443_B_MASK)) { 701 return nfc_hci_send_cmd(hdev, target->hci_reader_gate, 702 PN544_RF_READER_CMD_PRESENCE_CHECK, 703 NULL, 0, NULL); 704 } else if (target->supported_protocols & NFC_PROTO_MIFARE_MASK) { 705 if (target->nfcid1_len != 4 && target->nfcid1_len != 7 && 706 target->nfcid1_len != 10) --- 20 unchanged lines hidden (view full) --- 727 * 1: driver does not handle the event, please do standard processing 728 */ 729static int pn544_hci_event_received(struct nfc_hci_dev *hdev, u8 gate, u8 event, 730 struct sk_buff *skb) 731{ 732 struct sk_buff *rgb_skb = NULL; 733 int r; 734 |
733 pr_debug("hci event %d", event); | 735 pr_debug("hci event %d\n", event); |
734 switch (event) { 735 case PN544_HCI_EVT_ACTIVATED: 736 if (gate == PN544_RF_READER_NFCIP1_INITIATOR_GATE) { 737 r = nfc_hci_target_discovered(hdev, gate); 738 } else if (gate == PN544_RF_READER_NFCIP1_TARGET_GATE) { 739 r = nfc_hci_get_param(hdev, gate, PN544_DEP_ATR_REQ, 740 &rgb_skb); 741 if (r < 0) --- 14 unchanged lines hidden (view full) --- 756 break; 757 case PN544_HCI_EVT_RCV_DATA: 758 if (skb->len < 2) { 759 r = -EPROTO; 760 goto exit; 761 } 762 763 if (skb->data[0] != 0) { | 736 switch (event) { 737 case PN544_HCI_EVT_ACTIVATED: 738 if (gate == PN544_RF_READER_NFCIP1_INITIATOR_GATE) { 739 r = nfc_hci_target_discovered(hdev, gate); 740 } else if (gate == PN544_RF_READER_NFCIP1_TARGET_GATE) { 741 r = nfc_hci_get_param(hdev, gate, PN544_DEP_ATR_REQ, 742 &rgb_skb); 743 if (r < 0) --- 14 unchanged lines hidden (view full) --- 758 break; 759 case PN544_HCI_EVT_RCV_DATA: 760 if (skb->len < 2) { 761 r = -EPROTO; 762 goto exit; 763 } 764 765 if (skb->data[0] != 0) { |
764 pr_debug("data0 %d", skb->data[0]); | 766 pr_debug("data0 %d\n", skb->data[0]); |
765 r = -EPROTO; 766 goto exit; 767 } 768 769 skb_pull(skb, 2); 770 return nfc_tm_data_received(hdev->ndev, skb); 771 default: 772 return 1; --- 144 unchanged lines hidden (view full) --- 917{ 918 struct pn544_hci_info *info; 919 u32 protocols; 920 struct nfc_hci_init_data init_data; 921 int r; 922 923 info = kzalloc(sizeof(struct pn544_hci_info), GFP_KERNEL); 924 if (!info) { | 767 r = -EPROTO; 768 goto exit; 769 } 770 771 skb_pull(skb, 2); 772 return nfc_tm_data_received(hdev->ndev, skb); 773 default: 774 return 1; --- 144 unchanged lines hidden (view full) --- 919{ 920 struct pn544_hci_info *info; 921 u32 protocols; 922 struct nfc_hci_init_data init_data; 923 int r; 924 925 info = kzalloc(sizeof(struct pn544_hci_info), GFP_KERNEL); 926 if (!info) { |
925 pr_err("Cannot allocate memory for pn544_hci_info.\n"); | |
926 r = -ENOMEM; 927 goto err_info_alloc; 928 } 929 930 info->phy_ops = phy_ops; 931 info->phy_id = phy_id; 932 info->fw_download = fw_download; 933 info->state = PN544_ST_COLD; --- 16 unchanged lines hidden (view full) --- 950 NFC_PROTO_ISO14443_B_MASK | 951 NFC_PROTO_NFC_DEP_MASK; 952 953 info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data, 0, 954 protocols, llc_name, 955 phy_headroom + PN544_CMDS_HEADROOM, 956 phy_tailroom, phy_payload); 957 if (!info->hdev) { | 927 r = -ENOMEM; 928 goto err_info_alloc; 929 } 930 931 info->phy_ops = phy_ops; 932 info->phy_id = phy_id; 933 info->fw_download = fw_download; 934 info->state = PN544_ST_COLD; --- 16 unchanged lines hidden (view full) --- 951 NFC_PROTO_ISO14443_B_MASK | 952 NFC_PROTO_NFC_DEP_MASK; 953 954 info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data, 0, 955 protocols, llc_name, 956 phy_headroom + PN544_CMDS_HEADROOM, 957 phy_tailroom, phy_payload); 958 if (!info->hdev) { |
958 pr_err("Cannot allocate nfc hdev.\n"); | 959 pr_err("Cannot allocate nfc hdev\n"); |
959 r = -ENOMEM; 960 goto err_alloc_hdev; 961 } 962 963 nfc_hci_set_clientdata(info->hdev, info); 964 965 r = nfc_hci_register_device(info->hdev); 966 if (r) --- 29 unchanged lines hidden --- | 960 r = -ENOMEM; 961 goto err_alloc_hdev; 962 } 963 964 nfc_hci_set_clientdata(info->hdev, info); 965 966 r = nfc_hci_register_device(info->hdev); 967 if (r) --- 29 unchanged lines hidden --- |