NFC Digital: Add NFC-F technology support
[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
4b10884e
TE
25#define PR_DBG(fmt, ...) pr_debug("%s: " fmt "\n", __func__, ##__VA_ARGS__)
26#define PR_ERR(fmt, ...) pr_err("%s: " fmt "\n", __func__, ##__VA_ARGS__)
27#define PROTOCOL_ERR(req) pr_err("%s:%d: NFC Digital Protocol error: %s\n", \
28 __func__, __LINE__, req)
29
59ee2361
TE
30#define DIGITAL_CMD_IN_SEND 0
31#define DIGITAL_CMD_TG_SEND 1
32#define DIGITAL_CMD_TG_LISTEN 2
33#define DIGITAL_CMD_TG_LISTEN_MDAA 3
34
35#define DIGITAL_MAX_HEADER_LEN 7
36#define DIGITAL_CRC_LEN 2
37
2c66daec
TE
38#define DIGITAL_DRV_CAPS_IN_CRC(ddev) \
39 ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_IN_CRC)
40#define DIGITAL_DRV_CAPS_TG_CRC(ddev) \
41 ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_TG_CRC)
42
43struct digital_data_exch {
44 data_exchange_cb_t cb;
45 void *cb_context;
46};
47
59ee2361
TE
48struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev,
49 unsigned int len);
50
51int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type,
52 struct sk_buff *skb, u16 timeout,
53 nfc_digital_cmd_complete_t cmd_cb, void *cb_context);
54
55int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param);
56static inline int digital_in_send_cmd(struct nfc_digital_dev *ddev,
57 struct sk_buff *skb, u16 timeout,
58 nfc_digital_cmd_complete_t cmd_cb,
59 void *cb_context)
60{
61 return digital_send_cmd(ddev, DIGITAL_CMD_IN_SEND, skb, timeout, cmd_cb,
62 cb_context);
63}
64
65void digital_poll_next_tech(struct nfc_digital_dev *ddev);
66
67int digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech);
8c0695e4 68int digital_in_send_sensf_req(struct nfc_digital_dev *ddev, u8 rf_tech);
59ee2361 69
2c66daec
TE
70int digital_target_found(struct nfc_digital_dev *ddev,
71 struct nfc_target *target, u8 protocol);
72
73int digital_in_recv_mifare_res(struct sk_buff *resp);
74
75typedef u16 (*crc_func_t)(u16, const u8 *, size_t);
76
77#define CRC_A_INIT 0x6363
78#define CRC_B_INIT 0xFFFF
8c0695e4 79#define CRC_F_INIT 0x0000
2c66daec
TE
80
81void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init,
82 u8 bitwise_inv, u8 msb_first);
83
84static inline void digital_skb_add_crc_a(struct sk_buff *skb)
85{
86 digital_skb_add_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
87}
88
89static inline void digital_skb_add_crc_b(struct sk_buff *skb)
90{
91 digital_skb_add_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
92}
93
8c0695e4
TE
94static inline void digital_skb_add_crc_f(struct sk_buff *skb)
95{
96 digital_skb_add_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1);
97}
98
2c66daec
TE
99static inline void digital_skb_add_crc_none(struct sk_buff *skb)
100{
101 return;
102}
103
104int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func,
105 u16 crc_init, u8 bitwise_inv, u8 msb_first);
106
107static inline int digital_skb_check_crc_a(struct sk_buff *skb)
108{
109 return digital_skb_check_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
110}
111
112static inline int digital_skb_check_crc_b(struct sk_buff *skb)
113{
114 return digital_skb_check_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
115}
116
8c0695e4
TE
117static inline int digital_skb_check_crc_f(struct sk_buff *skb)
118{
119 return digital_skb_check_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1);
120}
121
2c66daec
TE
122static inline int digital_skb_check_crc_none(struct sk_buff *skb)
123{
124 return 0;
125}
126
4b10884e 127#endif /* __DIGITAL_H */
This page took 0.029958 seconds and 5 git commands to generate.