NFC: digital: Add poll support for type 4A tag platform
[deliverable/linux.git] / net / nfc / digital.h
CommitLineData
4b10884e
TE
1/*
2 * NFC Digital Protocol stack
3 * Copyright (c) 2013, Intel Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
14 */
15
16#ifndef __DIGITAL_H
17#define __DIGITAL_H
18
19#include <net/nfc/nfc.h>
20#include <net/nfc/digital.h>
21
2c66daec 22#include <linux/crc-ccitt.h>
8c0695e4 23#include <linux/crc-itu-t.h>
2c66daec 24
c5da0e4a
SO
25#define PROTOCOL_ERR(req) pr_err("%d: NFC Digital Protocol error: %s\n", \
26 __LINE__, req)
4b10884e 27
59ee2361
TE
28#define DIGITAL_CMD_IN_SEND 0
29#define DIGITAL_CMD_TG_SEND 1
30#define DIGITAL_CMD_TG_LISTEN 2
31#define DIGITAL_CMD_TG_LISTEN_MDAA 3
32
33#define DIGITAL_MAX_HEADER_LEN 7
34#define DIGITAL_CRC_LEN 2
35
7d0911c0
TE
36#define DIGITAL_SENSF_NFCID2_NFC_DEP_B1 0x01
37#define DIGITAL_SENSF_NFCID2_NFC_DEP_B2 0xFE
38
39#define DIGITAL_SENS_RES_NFC_DEP 0x0100
40#define DIGITAL_SEL_RES_NFC_DEP 0x40
41#define DIGITAL_SENSF_FELICA_SC 0xFFFF
42
2c66daec
TE
43#define DIGITAL_DRV_CAPS_IN_CRC(ddev) \
44 ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_IN_CRC)
45#define DIGITAL_DRV_CAPS_TG_CRC(ddev) \
46 ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_TG_CRC)
47
48struct digital_data_exch {
49 data_exchange_cb_t cb;
50 void *cb_context;
51};
52
59ee2361
TE
53struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev,
54 unsigned int len);
55
56int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type,
1c7a4c24
TE
57 struct sk_buff *skb, struct digital_tg_mdaa_params *params,
58 u16 timeout, nfc_digital_cmd_complete_t cmd_cb,
59 void *cb_context);
59ee2361
TE
60
61int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param);
62static inline int digital_in_send_cmd(struct nfc_digital_dev *ddev,
63 struct sk_buff *skb, u16 timeout,
64 nfc_digital_cmd_complete_t cmd_cb,
65 void *cb_context)
66{
1c7a4c24
TE
67 return digital_send_cmd(ddev, DIGITAL_CMD_IN_SEND, skb, NULL, timeout,
68 cmd_cb, cb_context);
59ee2361
TE
69}
70
71void digital_poll_next_tech(struct nfc_digital_dev *ddev);
72
73int digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech);
8c0695e4 74int digital_in_send_sensf_req(struct nfc_digital_dev *ddev, u8 rf_tech);
a381d482 75int digital_in_send_iso15693_inv_req(struct nfc_digital_dev *ddev, u8 rf_tech);
59ee2361 76
2c66daec
TE
77int digital_target_found(struct nfc_digital_dev *ddev,
78 struct nfc_target *target, u8 protocol);
79
80int digital_in_recv_mifare_res(struct sk_buff *resp);
81
7d0911c0
TE
82int digital_in_send_atr_req(struct nfc_digital_dev *ddev,
83 struct nfc_target *target, __u8 comm_mode, __u8 *gb,
84 size_t gb_len);
85int digital_in_send_dep_req(struct nfc_digital_dev *ddev,
86 struct nfc_target *target, struct sk_buff *skb,
87 struct digital_data_exch *data_exch);
88
1c7a4c24
TE
89int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param);
90static inline int digital_tg_send_cmd(struct nfc_digital_dev *ddev,
91 struct sk_buff *skb, u16 timeout,
92 nfc_digital_cmd_complete_t cmd_cb, void *cb_context)
93{
94 return digital_send_cmd(ddev, DIGITAL_CMD_TG_SEND, skb, NULL, timeout,
95 cmd_cb, cb_context);
96}
97
98void digital_tg_recv_sens_req(struct nfc_digital_dev *ddev, void *arg,
99 struct sk_buff *resp);
100
101void digital_tg_recv_sensf_req(struct nfc_digital_dev *ddev, void *arg,
102 struct sk_buff *resp);
103
104static inline int digital_tg_listen(struct nfc_digital_dev *ddev, u16 timeout,
105 nfc_digital_cmd_complete_t cb, void *arg)
106{
107 return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN, NULL, NULL,
108 timeout, cb, arg);
109}
110
111void digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg,
112 struct sk_buff *resp);
113
114int digital_tg_send_dep_res(struct nfc_digital_dev *ddev, struct sk_buff *skb);
115
116int digital_tg_listen_nfca(struct nfc_digital_dev *ddev, u8 rf_tech);
117int digital_tg_listen_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech);
118
2c66daec
TE
119typedef u16 (*crc_func_t)(u16, const u8 *, size_t);
120
121#define CRC_A_INIT 0x6363
122#define CRC_B_INIT 0xFFFF
8c0695e4 123#define CRC_F_INIT 0x0000
2c66daec
TE
124
125void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init,
126 u8 bitwise_inv, u8 msb_first);
127
128static inline void digital_skb_add_crc_a(struct sk_buff *skb)
129{
130 digital_skb_add_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
131}
132
133static inline void digital_skb_add_crc_b(struct sk_buff *skb)
134{
135 digital_skb_add_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
136}
137
8c0695e4
TE
138static inline void digital_skb_add_crc_f(struct sk_buff *skb)
139{
140 digital_skb_add_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1);
141}
142
2c66daec
TE
143static inline void digital_skb_add_crc_none(struct sk_buff *skb)
144{
145 return;
146}
147
148int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func,
149 u16 crc_init, u8 bitwise_inv, u8 msb_first);
150
151static inline int digital_skb_check_crc_a(struct sk_buff *skb)
152{
153 return digital_skb_check_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
154}
155
156static inline int digital_skb_check_crc_b(struct sk_buff *skb)
157{
158 return digital_skb_check_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
159}
160
8c0695e4
TE
161static inline int digital_skb_check_crc_f(struct sk_buff *skb)
162{
163 return digital_skb_check_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1);
164}
165
2c66daec
TE
166static inline int digital_skb_check_crc_none(struct sk_buff *skb)
167{
168 return 0;
169}
170
4b10884e 171#endif /* __DIGITAL_H */
This page took 0.053969 seconds and 5 git commands to generate.