st-nci.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * NCI based Driver for STMicroelectronics NFC Chip
  3. *
  4. * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __LOCAL_ST_NCI_H_
  19. #define __LOCAL_ST_NCI_H_
  20. #include "ndlc.h"
  21. /* Define private flags: */
  22. #define ST_NCI_RUNNING 1
  23. #define ST_NCI_CORE_PROP 0x01
  24. #define ST_NCI_SET_NFC_MODE 0x02
  25. /*
  26. * ref ISO7816-3 chap 8.1. the initial character TS is followed by a
  27. * sequence of at most 32 characters.
  28. */
  29. #define ST_NCI_ESE_MAX_LENGTH 33
  30. #define ST_NCI_HCI_HOST_ID_ESE 0xc0
  31. #define ST_NCI_DEVICE_MGNT_GATE 0x01
  32. #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
  33. #define ST_NCI_FACTORY_MODE 2
  34. struct nci_mode_set_cmd {
  35. u8 cmd_type;
  36. u8 mode;
  37. } __packed;
  38. struct nci_mode_set_rsp {
  39. u8 status;
  40. } __packed;
  41. struct st_nci_se_status {
  42. bool is_ese_present;
  43. bool is_uicc_present;
  44. };
  45. struct st_nci_se_info {
  46. struct st_nci_se_status *se_status;
  47. u8 atr[ST_NCI_ESE_MAX_LENGTH];
  48. struct completion req_completion;
  49. struct timer_list bwi_timer;
  50. int wt_timeout; /* in msecs */
  51. bool bwi_active;
  52. struct timer_list se_active_timer;
  53. bool se_active;
  54. bool xch_error;
  55. se_io_cb_t cb;
  56. void *cb_context;
  57. };
  58. /**
  59. * enum nfc_vendor_cmds - supported nfc vendor commands
  60. *
  61. * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
  62. * are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
  63. * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
  64. * It does not consider any NFC_ATTR_VENDOR_DATA.
  65. * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
  66. * RF trimmings or low level drivers configurations (I2C, SPI, SWP).
  67. * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
  68. * table following RF technology, CLF mode or protocol.
  69. * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
  70. * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
  71. * level drivers configurations or RF trimmings.
  72. * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
  73. * packet can be more than 8KB.
  74. * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
  75. * configuration changes without CLF power off.
  76. * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
  77. * white list).
  78. * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
  79. * technology. When using this command to anti-collision is done.
  80. * @HCI_LOOPBACK: Allow to echo a command and test the Dh to CLF
  81. * connectivity.
  82. * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
  83. * CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
  84. * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
  85. * specific CLF command as there is no GPIO for this.
  86. * @HCI_DM_FWUPD_END: Allow to complete firmware update.
  87. * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
  88. * CLF antenna to a reference value.
  89. * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
  90. * received during a NCI_CORE_INIT_CMD.
  91. */
  92. enum nfc_vendor_cmds {
  93. FACTORY_MODE,
  94. HCI_CLEAR_ALL_PIPES,
  95. HCI_DM_PUT_DATA,
  96. HCI_DM_UPDATE_AID,
  97. HCI_DM_GET_INFO,
  98. HCI_DM_GET_DATA,
  99. HCI_DM_DIRECT_LOAD,
  100. HCI_DM_RESET,
  101. HCI_GET_PARAM,
  102. HCI_DM_FIELD_GENERATOR,
  103. HCI_LOOPBACK,
  104. HCI_DM_FWUPD_START,
  105. HCI_DM_FWUPD_END,
  106. HCI_DM_VDC_MEASUREMENT_VALUE,
  107. HCI_DM_VDC_VALUE_COMPARISON,
  108. MANUFACTURER_SPECIFIC,
  109. };
  110. struct st_nci_vendor_info {
  111. struct completion req_completion;
  112. struct sk_buff *rx_skb;
  113. };
  114. struct st_nci_info {
  115. struct llt_ndlc *ndlc;
  116. unsigned long flags;
  117. struct st_nci_se_info se_info;
  118. struct st_nci_vendor_info vendor_info;
  119. };
  120. void st_nci_remove(struct nci_dev *ndev);
  121. int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
  122. int phy_tailroom, struct st_nci_se_status *se_status);
  123. int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
  124. void st_nci_se_deinit(struct nci_dev *ndev);
  125. int st_nci_discover_se(struct nci_dev *ndev);
  126. int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
  127. int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
  128. int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
  129. u8 *apdu, size_t apdu_length,
  130. se_io_cb_t cb, void *cb_context);
  131. int st_nci_hci_load_session(struct nci_dev *ndev);
  132. void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
  133. u8 event, struct sk_buff *skb);
  134. void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
  135. struct sk_buff *skb);
  136. void st_nci_hci_loopback_event_received(struct nci_dev *ndev, u8 event,
  137. struct sk_buff *skb);
  138. int st_nci_vendor_cmds_init(struct nci_dev *ndev);
  139. #endif /* __LOCAL_ST_NCI_H_ */