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 #ifndef __NFC_DIGITAL_H
17 #define __NFC_DIGITAL_H
19 #include <linux/skbuff.h>
20 #include <net/nfc/nfc.h>
23 * Configuration types for in_configure_hw and tg_configure_hw.
26 NFC_DIGITAL_CONFIG_RF_TECH = 0,
27 NFC_DIGITAL_CONFIG_FRAMING,
31 * RF technology values passed as param argument to in_configure_hw and
32 * tg_configure_hw for NFC_DIGITAL_CONFIG_RF_TECH configuration type.
35 NFC_DIGITAL_RF_TECH_106A = 0,
36 NFC_DIGITAL_RF_TECH_212F,
37 NFC_DIGITAL_RF_TECH_424F,
38 NFC_DIGITAL_RF_TECH_ISO15693,
39 NFC_DIGITAL_RF_TECH_106B,
41 NFC_DIGITAL_RF_TECH_LAST,
45 * Framing configuration passed as param argument to in_configure_hw and
46 * tg_configure_hw for NFC_DIGITAL_CONFIG_FRAMING configuration type.
49 NFC_DIGITAL_FRAMING_NFCA_SHORT = 0,
50 NFC_DIGITAL_FRAMING_NFCA_STANDARD,
51 NFC_DIGITAL_FRAMING_NFCA_STANDARD_WITH_CRC_A,
52 NFC_DIGITAL_FRAMING_NFCA_ANTICOL_COMPLETE,
54 NFC_DIGITAL_FRAMING_NFCA_T1T,
55 NFC_DIGITAL_FRAMING_NFCA_T2T,
56 NFC_DIGITAL_FRAMING_NFCA_T4T,
57 NFC_DIGITAL_FRAMING_NFCA_NFC_DEP,
59 NFC_DIGITAL_FRAMING_NFCF,
60 NFC_DIGITAL_FRAMING_NFCF_T3T,
61 NFC_DIGITAL_FRAMING_NFCF_NFC_DEP,
62 NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED,
64 NFC_DIGITAL_FRAMING_ISO15693_INVENTORY,
65 NFC_DIGITAL_FRAMING_ISO15693_T5T,
67 NFC_DIGITAL_FRAMING_NFCB,
68 NFC_DIGITAL_FRAMING_NFCB_T4T,
71 NFC_DIGITAL_FRAMING_LAST,
74 #define DIGITAL_MDAA_NFCID1_SIZE 3
76 struct digital_tg_mdaa_params {
78 u8 nfcid1[DIGITAL_MDAA_NFCID1_SIZE];
81 u8 nfcid2[NFC_NFCID2_MAXSIZE];
85 struct nfc_digital_dev;
88 * nfc_digital_cmd_complete_t - Definition of command result callback
90 * @ddev: nfc_digital_device ref
92 * @resp: response data
94 * resp pointer can be an error code and will be checked with IS_ERR() macro.
95 * The callback is responsible for freeing resp sk_buff.
97 typedef void (*nfc_digital_cmd_complete_t)(struct nfc_digital_dev *ddev,
98 void *arg, struct sk_buff *resp);
101 * Device side NFC Digital operations
104 * @in_configure_hw: Hardware configuration for RF technology and communication
105 * framing in initiator mode. This is a synchronous function.
106 * @in_send_cmd: Initiator mode data exchange using RF technology and framing
107 * previously set with in_configure_hw. The peer response is returned
108 * through callback cb. If an io error occurs or the peer didn't reply
109 * within the specified timeout (ms), the error code is passed back through
110 * the resp pointer. This is an asynchronous function.
112 * Target mode: Only NFC-DEP protocol is supported in target mode.
113 * @tg_configure_hw: Hardware configuration for RF technology and communication
114 * framing in target mode. This is a synchronous function.
115 * @tg_send_cmd: Target mode data exchange using RF technology and framing
116 * previously set with tg_configure_hw. The peer next command is returned
117 * through callback cb. If an io error occurs or the peer didn't reply
118 * within the specified timeout (ms), the error code is passed back through
119 * the resp pointer. This is an asynchronous function.
120 * @tg_listen: Put the device in listen mode waiting for data from the peer
121 * device. This is an asynchronous function.
122 * @tg_listen_mdaa: If supported, put the device in automatic listen mode with
123 * mode detection and automatic anti-collision. In this mode, the device
124 * automatically detects the RF technology and executes the anti-collision
125 * detection using the command responses specified in mdaa_params. The
126 * mdaa_params structure contains SENS_RES, NFCID1, and SEL_RES for 106A RF
127 * tech. NFCID2 and system code (sc) for 212F and 424F. The driver returns
128 * the NFC-DEP ATR_REQ command through cb. The digital stack deducts the RF
129 * tech by analyzing the SoD of the frame containing the ATR_REQ command.
130 * This is an asynchronous function.
132 * @switch_rf: Turns device radio on or off. The stack does not call explicitly
133 * switch_rf to turn the radio on. A call to in|tg_configure_hw must turn
134 * the device radio on.
135 * @abort_cmd: Discard the last sent command.
137 * Notes: Asynchronous functions have a timeout parameter. It is the driver
138 * responsibility to call the digital stack back through the
139 * nfc_digital_cmd_complete_t callback when no RF respsonse has been
140 * received within the specified time (in milliseconds). In that case the
141 * driver must set the resp sk_buff to ERR_PTR(-ETIMEDOUT).
142 * Since the digital stack serializes commands to be sent, it's mandatory
143 * for the driver to handle the timeout correctly. Otherwise the stack
144 * would not be able to send new commands, waiting for the reply of the
147 struct nfc_digital_ops {
148 int (*in_configure_hw)(struct nfc_digital_dev *ddev, int type,
150 int (*in_send_cmd)(struct nfc_digital_dev *ddev, struct sk_buff *skb,
151 u16 timeout, nfc_digital_cmd_complete_t cb,
154 int (*tg_configure_hw)(struct nfc_digital_dev *ddev, int type,
156 int (*tg_send_cmd)(struct nfc_digital_dev *ddev, struct sk_buff *skb,
157 u16 timeout, nfc_digital_cmd_complete_t cb,
159 int (*tg_listen)(struct nfc_digital_dev *ddev, u16 timeout,
160 nfc_digital_cmd_complete_t cb, void *arg);
161 int (*tg_listen_mdaa)(struct nfc_digital_dev *ddev,
162 struct digital_tg_mdaa_params *mdaa_params,
163 u16 timeout, nfc_digital_cmd_complete_t cb,
166 int (*switch_rf)(struct nfc_digital_dev *ddev, bool on);
167 void (*abort_cmd)(struct nfc_digital_dev *ddev);
170 #define NFC_DIGITAL_POLL_MODE_COUNT_MAX 6 /* 106A, 212F, and 424F in & tg */
172 typedef int (*digital_poll_t)(struct nfc_digital_dev *ddev, u8 rf_tech);
174 struct digital_poll_tech {
176 digital_poll_t poll_func;
180 * Driver capabilities - bit mask made of the following values
182 * @NFC_DIGITAL_DRV_CAPS_IN_CRC: The driver handles CRC calculation in initiator
184 * @NFC_DIGITAL_DRV_CAPS_TG_CRC: The driver handles CRC calculation in target
187 #define NFC_DIGITAL_DRV_CAPS_IN_CRC 0x0001
188 #define NFC_DIGITAL_DRV_CAPS_TG_CRC 0x0002
190 struct nfc_digital_dev {
191 struct nfc_dev *nfc_dev;
192 struct nfc_digital_ops *ops;
199 u32 driver_capabilities;
202 struct digital_poll_tech poll_techs[NFC_DIGITAL_POLL_MODE_COUNT_MAX];
205 struct mutex poll_lock;
207 struct work_struct cmd_work;
208 struct work_struct cmd_complete_work;
209 struct list_head cmd_queue;
210 struct mutex cmd_lock;
212 struct work_struct poll_work;
220 int (*skb_check_crc)(struct sk_buff *skb);
221 void (*skb_add_crc)(struct sk_buff *skb);
224 struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops,
225 __u32 supported_protocols,
226 __u32 driver_capabilities,
229 void nfc_digital_free_device(struct nfc_digital_dev *ndev);
230 int nfc_digital_register_device(struct nfc_digital_dev *ndev);
231 void nfc_digital_unregister_device(struct nfc_digital_dev *ndev);
233 static inline void nfc_digital_set_parent_dev(struct nfc_digital_dev *ndev,
236 nfc_set_parent_dev(ndev->nfc_dev, dev);
239 static inline void nfc_digital_set_drvdata(struct nfc_digital_dev *dev,
242 dev->driver_data = data;
245 static inline void *nfc_digital_get_drvdata(struct nfc_digital_dev *dev)
247 return dev->driver_data;
250 #endif /* __NFC_DIGITAL_H */