digital.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. #include <linux/crc-itu-t.h>
  21. #define PROTOCOL_ERR(req) pr_err("%d: NFC Digital Protocol error: %s\n", \
  22. __LINE__, req)
  23. #define DIGITAL_CMD_IN_SEND 0
  24. #define DIGITAL_CMD_TG_SEND 1
  25. #define DIGITAL_CMD_TG_LISTEN 2
  26. #define DIGITAL_CMD_TG_LISTEN_MDAA 3
  27. #define DIGITAL_MAX_HEADER_LEN 7
  28. #define DIGITAL_CRC_LEN 2
  29. #define DIGITAL_SENSF_NFCID2_NFC_DEP_B1 0x01
  30. #define DIGITAL_SENSF_NFCID2_NFC_DEP_B2 0xFE
  31. #define DIGITAL_SENS_RES_NFC_DEP 0x0100
  32. #define DIGITAL_SEL_RES_NFC_DEP 0x40
  33. #define DIGITAL_SENSF_FELICA_SC 0xFFFF
  34. #define DIGITAL_DRV_CAPS_IN_CRC(ddev) \
  35. ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_IN_CRC)
  36. #define DIGITAL_DRV_CAPS_TG_CRC(ddev) \
  37. ((ddev)->driver_capabilities & NFC_DIGITAL_DRV_CAPS_TG_CRC)
  38. struct digital_data_exch {
  39. data_exchange_cb_t cb;
  40. void *cb_context;
  41. };
  42. struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev,
  43. unsigned int len);
  44. int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type,
  45. struct sk_buff *skb, struct digital_tg_mdaa_params *params,
  46. u16 timeout, nfc_digital_cmd_complete_t cmd_cb,
  47. void *cb_context);
  48. int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param);
  49. static inline int digital_in_send_cmd(struct nfc_digital_dev *ddev,
  50. struct sk_buff *skb, u16 timeout,
  51. nfc_digital_cmd_complete_t cmd_cb,
  52. void *cb_context)
  53. {
  54. return digital_send_cmd(ddev, DIGITAL_CMD_IN_SEND, skb, NULL, timeout,
  55. cmd_cb, cb_context);
  56. }
  57. void digital_poll_next_tech(struct nfc_digital_dev *ddev);
  58. int digital_in_send_sens_req(struct nfc_digital_dev *ddev, u8 rf_tech);
  59. int digital_in_send_sensf_req(struct nfc_digital_dev *ddev, u8 rf_tech);
  60. int digital_target_found(struct nfc_digital_dev *ddev,
  61. struct nfc_target *target, u8 protocol);
  62. int digital_in_recv_mifare_res(struct sk_buff *resp);
  63. int digital_in_send_atr_req(struct nfc_digital_dev *ddev,
  64. struct nfc_target *target, __u8 comm_mode, __u8 *gb,
  65. size_t gb_len);
  66. int digital_in_send_dep_req(struct nfc_digital_dev *ddev,
  67. struct nfc_target *target, struct sk_buff *skb,
  68. struct digital_data_exch *data_exch);
  69. int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param);
  70. static inline int digital_tg_send_cmd(struct nfc_digital_dev *ddev,
  71. struct sk_buff *skb, u16 timeout,
  72. nfc_digital_cmd_complete_t cmd_cb, void *cb_context)
  73. {
  74. return digital_send_cmd(ddev, DIGITAL_CMD_TG_SEND, skb, NULL, timeout,
  75. cmd_cb, cb_context);
  76. }
  77. void digital_tg_recv_sens_req(struct nfc_digital_dev *ddev, void *arg,
  78. struct sk_buff *resp);
  79. void digital_tg_recv_sensf_req(struct nfc_digital_dev *ddev, void *arg,
  80. struct sk_buff *resp);
  81. static inline int digital_tg_listen(struct nfc_digital_dev *ddev, u16 timeout,
  82. nfc_digital_cmd_complete_t cb, void *arg)
  83. {
  84. return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN, NULL, NULL,
  85. timeout, cb, arg);
  86. }
  87. void digital_tg_recv_atr_req(struct nfc_digital_dev *ddev, void *arg,
  88. struct sk_buff *resp);
  89. int digital_tg_send_dep_res(struct nfc_digital_dev *ddev, struct sk_buff *skb);
  90. int digital_tg_listen_nfca(struct nfc_digital_dev *ddev, u8 rf_tech);
  91. int digital_tg_listen_nfcf(struct nfc_digital_dev *ddev, u8 rf_tech);
  92. typedef u16 (*crc_func_t)(u16, const u8 *, size_t);
  93. #define CRC_A_INIT 0x6363
  94. #define CRC_B_INIT 0xFFFF
  95. #define CRC_F_INIT 0x0000
  96. void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init,
  97. u8 bitwise_inv, u8 msb_first);
  98. static inline void digital_skb_add_crc_a(struct sk_buff *skb)
  99. {
  100. digital_skb_add_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
  101. }
  102. static inline void digital_skb_add_crc_b(struct sk_buff *skb)
  103. {
  104. digital_skb_add_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
  105. }
  106. static inline void digital_skb_add_crc_f(struct sk_buff *skb)
  107. {
  108. digital_skb_add_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1);
  109. }
  110. static inline void digital_skb_add_crc_none(struct sk_buff *skb)
  111. {
  112. return;
  113. }
  114. int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func,
  115. u16 crc_init, u8 bitwise_inv, u8 msb_first);
  116. static inline int digital_skb_check_crc_a(struct sk_buff *skb)
  117. {
  118. return digital_skb_check_crc(skb, crc_ccitt, CRC_A_INIT, 0, 0);
  119. }
  120. static inline int digital_skb_check_crc_b(struct sk_buff *skb)
  121. {
  122. return digital_skb_check_crc(skb, crc_ccitt, CRC_B_INIT, 1, 0);
  123. }
  124. static inline int digital_skb_check_crc_f(struct sk_buff *skb)
  125. {
  126. return digital_skb_check_crc(skb, crc_itu_t, CRC_F_INIT, 0, 1);
  127. }
  128. static inline int digital_skb_check_crc_none(struct sk_buff *skb)
  129. {
  130. return 0;
  131. }
  132. #endif /* __DIGITAL_H */