digital.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef __DIGITAL_H
  16. #define __DIGITAL_H
  17. #include <net/nfc/nfc.h>
  18. #include <net/nfc/digital.h>
  19. #include <linux/crc-ccitt.h>
  20. #define PR_DBG(fmt, ...) pr_debug("%s: " fmt "\n", __func__, ##__VA_ARGS__)
  21. #define PR_ERR(fmt, ...) pr_err("%s: " fmt "\n", __func__, ##__VA_ARGS__)
  22. #define PROTOCOL_ERR(req) pr_err("%s:%d: NFC Digital Protocol error: %s\n", \
  23. __func__, __LINE__, req)
  24. #define DIGITAL_CMD_IN_SEND 0
  25. #define DIGITAL_CMD_TG_SEND 1
  26. #define DIGITAL_CMD_TG_LISTEN 2
  27. #define DIGITAL_CMD_TG_LISTEN_MDAA 3
  28. #define DIGITAL_MAX_HEADER_LEN 7
  29. #define DIGITAL_CRC_LEN 2
  30. #define DIGITAL_DRV_CAPS_IN_CRC(ddev) \
  31. ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_IN_CRC)
  32. #define DIGITAL_DRV_CAPS_TG_CRC(ddev) \
  33. ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_TG_CRC)
  34. struct digital_data_exch {
  35. data_exchange_cb_t cb;
  36. void *cb_context;
  37. };
  38. struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev,
  39. unsigned int len);
  40. int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type,
  41. struct sk_buff *skb, u16 timeout,
  42. nfc_digital_cmd_complete_t cmd_cb, void *cb_context);
  43. int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param);
  44. static inline int digital_in_send_cmd(struct nfc_digital_dev *ddev,
  45. struct sk_buff *skb, u16 timeout,
  46. nfc_digital_cmd_complete_t cmd_cb,
  47. void *cb_context)
  48. {
  49. return digital_send_cmd(ddev, DIGITAL_CMD_IN_SEND, skb, timeout, cmd_cb,
  50. cb_context);
  51. }
  52. void digital_poll_next_tech(struct nfc_digital_dev *ddev);
  53. int digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech);
  54. int digital_target_found(struct nfc_digital_dev *ddev,
  55. struct nfc_target *target, u8 protocol);
  56. int digital_in_recv_mifare_res(struct sk_buff *resp);
  57. typedef u16 (*crc_func_t)(u16, const u8 *, size_t);
  58. #define CRC_A_INIT 0x6363
  59. #define CRC_B_INIT 0xFFFF
  60. void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init,
  61. u8 bitwise_inv, u8 msb_first);
  62. static inline void digital_skb_add_crc_a(struct sk_buff *skb)
  63. {
  64. digital_skb_add_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
  65. }
  66. static inline void digital_skb_add_crc_b(struct sk_buff *skb)
  67. {
  68. digital_skb_add_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
  69. }
  70. static inline void digital_skb_add_crc_none(struct sk_buff *skb)
  71. {
  72. return;
  73. }
  74. int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func,
  75. u16 crc_init, u8 bitwise_inv, u8 msb_first);
  76. static inline int digital_skb_check_crc_a(struct sk_buff *skb)
  77. {
  78. return digital_skb_check_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
  79. }
  80. static inline int digital_skb_check_crc_b(struct sk_buff *skb)
  81. {
  82. return digital_skb_check_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
  83. }
  84. static inline int digital_skb_check_crc_none(struct sk_buff *skb)
  85. {
  86. return 0;
  87. }
  88. #endif /* __DIGITAL_H */