st-nci.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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_DEVICE_MGNT_GATE 0x01
  31. #define ST_NCI_VENDOR_OUI 0x0080E1 /* STMicroelectronics */
  32. #define ST_NCI_FACTORY_MODE 2
  33. struct nci_mode_set_cmd {
  34. u8 cmd_type;
  35. u8 mode;
  36. } __packed;
  37. struct nci_mode_set_rsp {
  38. u8 status;
  39. } __packed;
  40. struct st_nci_se_status {
  41. bool is_ese_present;
  42. bool is_uicc_present;
  43. };
  44. struct st_nci_se_info {
  45. struct st_nci_se_status *se_status;
  46. u8 atr[ST_NCI_ESE_MAX_LENGTH];
  47. struct completion req_completion;
  48. struct timer_list bwi_timer;
  49. int wt_timeout; /* in msecs */
  50. bool bwi_active;
  51. struct timer_list se_active_timer;
  52. bool se_active;
  53. bool xch_error;
  54. se_io_cb_t cb;
  55. void *cb_context;
  56. };
  57. /**
  58. * enum nfc_vendor_cmds - supported nfc vendor commands
  59. *
  60. * @FACTORY_MODE: Allow to set the driver into a mode where no secure element
  61. * are activated. It does not consider any NFC_ATTR_VENDOR_DATA.
  62. * @HCI_CLEAR_ALL_PIPES: Allow to execute a HCI clear all pipes command.
  63. * It does not consider any NFC_ATTR_VENDOR_DATA.
  64. * @HCI_DM_PUT_DATA: Allow to configure specific CLF registry as for example
  65. * RF trimmings or low level drivers configurations (I2C, SPI, SWP).
  66. * @HCI_DM_UPDATE_AID: Allow to configure an AID routing into the CLF routing
  67. * table following RF technology, CLF mode or protocol.
  68. * @HCI_DM_GET_INFO: Allow to retrieve CLF information.
  69. * @HCI_DM_GET_DATA: Allow to retrieve CLF configurable data such as low
  70. * level drivers configurations or RF trimmings.
  71. * @HCI_DM_DIRECT_LOAD: Allow to load a firmware into the CLF. A complete
  72. * packet can be more than 8KB.
  73. * @HCI_DM_RESET: Allow to run a CLF reset in order to "commit" CLF
  74. * configuration changes without CLF power off.
  75. * @HCI_GET_PARAM: Allow to retrieve an HCI CLF parameter (for example the
  76. * white list).
  77. * @HCI_DM_FIELD_GENERATOR: Allow to generate different kind of RF
  78. * technology. When using this command to anti-collision is done.
  79. * @LOOPBACK: Allow to echo a command and test the Dh to CLF connectivity.
  80. * @HCI_DM_VDC_MEASUREMENT_VALUE: Allow to measure the field applied on the
  81. * CLF antenna. A value between 0 and 0x0f is returned. 0 is maximum.
  82. * @HCI_DM_FWUPD_START: Allow to put CLF into firmware update mode. It is a
  83. * specific CLF command as there is no GPIO for this.
  84. * @HCI_DM_FWUPD_END: Allow to complete firmware update.
  85. * @HCI_DM_VDC_VALUE_COMPARISON: Allow to compare the field applied on the
  86. * CLF antenna to a reference value.
  87. * @MANUFACTURER_SPECIFIC: Allow to retrieve manufacturer specific data
  88. * received during a NCI_CORE_INIT_CMD.
  89. */
  90. enum nfc_vendor_cmds {
  91. FACTORY_MODE,
  92. HCI_CLEAR_ALL_PIPES,
  93. HCI_DM_PUT_DATA,
  94. HCI_DM_UPDATE_AID,
  95. HCI_DM_GET_INFO,
  96. HCI_DM_GET_DATA,
  97. HCI_DM_DIRECT_LOAD,
  98. HCI_DM_RESET,
  99. HCI_GET_PARAM,
  100. HCI_DM_FIELD_GENERATOR,
  101. LOOPBACK,
  102. HCI_DM_FWUPD_START,
  103. HCI_DM_FWUPD_END,
  104. HCI_DM_VDC_MEASUREMENT_VALUE,
  105. HCI_DM_VDC_VALUE_COMPARISON,
  106. MANUFACTURER_SPECIFIC,
  107. };
  108. struct st_nci_info {
  109. struct llt_ndlc *ndlc;
  110. unsigned long flags;
  111. struct st_nci_se_info se_info;
  112. };
  113. void st_nci_remove(struct nci_dev *ndev);
  114. int st_nci_probe(struct llt_ndlc *ndlc, int phy_headroom,
  115. int phy_tailroom, struct st_nci_se_status *se_status);
  116. int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status);
  117. void st_nci_se_deinit(struct nci_dev *ndev);
  118. int st_nci_discover_se(struct nci_dev *ndev);
  119. int st_nci_enable_se(struct nci_dev *ndev, u32 se_idx);
  120. int st_nci_disable_se(struct nci_dev *ndev, u32 se_idx);
  121. int st_nci_se_io(struct nci_dev *ndev, u32 se_idx,
  122. u8 *apdu, size_t apdu_length,
  123. se_io_cb_t cb, void *cb_context);
  124. int st_nci_hci_load_session(struct nci_dev *ndev);
  125. void st_nci_hci_event_received(struct nci_dev *ndev, u8 pipe,
  126. u8 event, struct sk_buff *skb);
  127. void st_nci_hci_cmd_received(struct nci_dev *ndev, u8 pipe, u8 cmd,
  128. struct sk_buff *skb);
  129. int st_nci_vendor_cmds_init(struct nci_dev *ndev);
  130. #endif /* __LOCAL_ST_NCI_H_ */