Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 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 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame^] | 22 | #include <linux/crc-ccitt.h> |
| 23 | |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 24 | #define PR_DBG(fmt, ...) pr_debug("%s: " fmt "\n", __func__, ##__VA_ARGS__) |
| 25 | #define PR_ERR(fmt, ...) pr_err("%s: " fmt "\n", __func__, ##__VA_ARGS__) |
| 26 | #define PROTOCOL_ERR(req) pr_err("%s:%d: NFC Digital Protocol error: %s\n", \ |
| 27 | __func__, __LINE__, req) |
| 28 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 29 | #define DIGITAL_CMD_IN_SEND 0 |
| 30 | #define DIGITAL_CMD_TG_SEND 1 |
| 31 | #define DIGITAL_CMD_TG_LISTEN 2 |
| 32 | #define DIGITAL_CMD_TG_LISTEN_MDAA 3 |
| 33 | |
| 34 | #define DIGITAL_MAX_HEADER_LEN 7 |
| 35 | #define DIGITAL_CRC_LEN 2 |
| 36 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame^] | 37 | #define DIGITAL_DRV_CAPS_IN_CRC(ddev) \ |
| 38 | ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_IN_CRC) |
| 39 | #define DIGITAL_DRV_CAPS_TG_CRC(ddev) \ |
| 40 | ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_TG_CRC) |
| 41 | |
| 42 | struct digital_data_exch { |
| 43 | data_exchange_cb_t cb; |
| 44 | void *cb_context; |
| 45 | }; |
| 46 | |
Thierry Escande | 59ee236 | 2013-09-19 17:55:26 +0200 | [diff] [blame] | 47 | struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev, |
| 48 | unsigned int len); |
| 49 | |
| 50 | int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type, |
| 51 | struct sk_buff *skb, u16 timeout, |
| 52 | nfc_digital_cmd_complete_t cmd_cb, void *cb_context); |
| 53 | |
| 54 | int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param); |
| 55 | static inline int digital_in_send_cmd(struct nfc_digital_dev *ddev, |
| 56 | struct sk_buff *skb, u16 timeout, |
| 57 | nfc_digital_cmd_complete_t cmd_cb, |
| 58 | void *cb_context) |
| 59 | { |
| 60 | return digital_send_cmd(ddev, DIGITAL_CMD_IN_SEND, skb, timeout, cmd_cb, |
| 61 | cb_context); |
| 62 | } |
| 63 | |
| 64 | void digital_poll_next_tech(struct nfc_digital_dev *ddev); |
| 65 | |
| 66 | int digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech); |
| 67 | |
Thierry Escande | 2c66dae | 2013-09-19 17:55:27 +0200 | [diff] [blame^] | 68 | int digital_target_found(struct nfc_digital_dev *ddev, |
| 69 | struct nfc_target *target, u8 protocol); |
| 70 | |
| 71 | int digital_in_recv_mifare_res(struct sk_buff *resp); |
| 72 | |
| 73 | typedef u16 (*crc_func_t)(u16, const u8 *, size_t); |
| 74 | |
| 75 | #define CRC_A_INIT 0x6363 |
| 76 | #define CRC_B_INIT 0xFFFF |
| 77 | |
| 78 | void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init, |
| 79 | u8 bitwise_inv, u8 msb_first); |
| 80 | |
| 81 | static inline void digital_skb_add_crc_a(struct sk_buff *skb) |
| 82 | { |
| 83 | digital_skb_add_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0); |
| 84 | } |
| 85 | |
| 86 | static inline void digital_skb_add_crc_b(struct sk_buff *skb) |
| 87 | { |
| 88 | digital_skb_add_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0); |
| 89 | } |
| 90 | |
| 91 | static inline void digital_skb_add_crc_none(struct sk_buff *skb) |
| 92 | { |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func, |
| 97 | u16 crc_init, u8 bitwise_inv, u8 msb_first); |
| 98 | |
| 99 | static inline int digital_skb_check_crc_a(struct sk_buff *skb) |
| 100 | { |
| 101 | return digital_skb_check_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0); |
| 102 | } |
| 103 | |
| 104 | static inline int digital_skb_check_crc_b(struct sk_buff *skb) |
| 105 | { |
| 106 | return digital_skb_check_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0); |
| 107 | } |
| 108 | |
| 109 | static inline int digital_skb_check_crc_none(struct sk_buff *skb) |
| 110 | { |
| 111 | return 0; |
| 112 | } |
| 113 | |
Thierry Escande | 4b10884eb | 2013-09-19 17:55:25 +0200 | [diff] [blame] | 114 | #endif /* __DIGITAL_H */ |